runtime.bats 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bats
  2. SUT_IMAGE=bats-jenkins
  3. SUT_CONTAINER=bats-jenkins
  4. load 'test_helper/bats-support/load'
  5. load 'test_helper/bats-assert/load'
  6. load test_helpers
  7. @test "build image" {
  8. cd $BATS_TEST_DIRNAME/..
  9. docker_build -t $SUT_IMAGE .
  10. }
  11. @test "clean test containers" {
  12. cleanup $SUT_CONTAINER
  13. }
  14. @test "test multiple JENKINS_OPTS" {
  15. # running --help --version should return the version, not the help
  16. local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
  17. # need the last line of output
  18. assert "${version}" docker run --rm -e JENKINS_OPTS="--help --version" --name $SUT_CONTAINER -P $SUT_IMAGE | tail -n 1
  19. }
  20. @test "test jenkins arguments" {
  21. # running --help --version should return the version, not the help
  22. local version=$(grep 'ENV JENKINS_VERSION' Dockerfile | sed -e 's/.*:-\(.*\)}/\1/')
  23. # need the last line of output
  24. assert "${version}" docker run --rm --name $SUT_CONTAINER -P $SUT_IMAGE --help --version | tail -n 1
  25. }
  26. @test "create test container" {
  27. docker run -d -e JAVA_OPTS="-Duser.timezone=Europe/Madrid -Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';\"" --name $SUT_CONTAINER -P $SUT_IMAGE
  28. }
  29. @test "test container is running" {
  30. sleep 1 # give time to eventually fail to initialize
  31. retry 3 1 assert "true" docker inspect -f {{.State.Running}} $SUT_CONTAINER
  32. }
  33. @test "Jenkins is initialized" {
  34. retry 30 5 test_url /api/json
  35. }
  36. @test "JAVA_OPTS are set" {
  37. local sed_expr='s/<wbr>//g;s/<td class="pane">.*<\/td><td class.*normal">//g;s/<t.>//g;s/<\/t.>//g'
  38. assert 'default-src &#039;self&#039;; script-src &#039;self&#039; &#039;unsafe-inline&#039; &#039;unsafe-eval&#039;; style-src &#039;self&#039; &#039;unsafe-inline&#039;;' \
  39. bash -c "curl -fsSL --user \"admin:$(get_jenkins_password)\" $(get_jenkins_url)/systemInfo | sed 's/<\/tr>/<\/tr>\'$'\n/g' | grep '<td class=\"pane\">hudson.model.DirectoryBrowserSupport.CSP</td>' | sed -e '${sed_expr}'"
  40. assert 'Europe/Madrid' \
  41. bash -c "curl -fsSL --user \"admin:$(get_jenkins_password)\" $(get_jenkins_url)/systemInfo | sed 's/<\/tr>/<\/tr>\'$'\n/g' | grep '<td class=\"pane\">user.timezone</td>' | sed -e '${sed_expr}'"
  42. }
  43. @test "clean test containers" {
  44. cleanup $SUT_CONTAINER
  45. }