From d97234ff6bcca5f2be71495c7fd5040eae59cd37 Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Mon, 10 Dec 2018 21:13:03 +0000 Subject: [PATCH] Modifying slow-server tests to use setup The slow server tests are using the global setup to create the test dependencies, like setting up the web server. Recently a function to set the upstream server in a test environment was added to the test library which now makes possible to configure the environment to use this server after it's been created so we no longer need to create the web server in the global setup. This commit moves the creation of the web server to the test_setup function to make the code from the tests easier to read and less convoluted. Signed-off-by: Castulo Martinez --- .../checkupdate/chk-update-slow-server.bats | 15 +++++---------- test/functional/update/update-slow-server.bats | 17 ++++++----------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/test/functional/checkupdate/chk-update-slow-server.bats b/test/functional/checkupdate/chk-update-slow-server.bats index 12d23a7c..71257ca7 100755 --- a/test/functional/checkupdate/chk-update-slow-server.bats +++ b/test/functional/checkupdate/chk-update-slow-server.bats @@ -2,33 +2,28 @@ load "../testlib" -global_setup() { +test_setup() { create_test_environment "$TEST_NAME" create_version "$TEST_NAME" 99990 10 staging # start slow response web server start_web_server -s -} -test_setup() { + # Set the web server as our upstream server + port=$(get_web_server_port "$TEST_NAME") + set_upstream_server "$TEST_NAME" "http://localhost:$port/$TEST_NAME/web-dir" - return } test_teardown() { - return -} - -global_teardown() { - destroy_test_environment "$TEST_NAME" } @test "CHK003: Check for available updates with a slow server" { - run sudo sh -c "$SWUPD check-update $SWUPD_OPTS_HTTP" + run sudo sh -c "$SWUPD check-update $SWUPD_OPTS" assert_status_is 0 expected_output=$(cat <<-EOM Current OS version: 10 diff --git a/test/functional/update/update-slow-server.bats b/test/functional/update/update-slow-server.bats index 41a5f50b..8d9ecef6 100755 --- a/test/functional/update/update-slow-server.bats +++ b/test/functional/update/update-slow-server.bats @@ -2,8 +2,7 @@ load "../testlib" -global_setup() { - +test_setup() { # Skip this test if not running in Travis CI, because test takes too long for # local development. To run this locally do: TRAVIS=true make check if [ -z "${TRAVIS}" ]; then @@ -15,18 +14,14 @@ global_setup() { update_bundle "$TEST_NAME" test-bundle --update /foo/bar start_web_server -d pack-test-bundle-from-10.tar -s -} -test_setup() { - return + # Set the web server as our upstream server + port=$(get_web_server_port "$TEST_NAME") + set_upstream_server "$TEST_NAME" "http://localhost:$port/$TEST_NAME/web-dir" + } test_teardown() { - return -} - -global_teardown() { - # teardown only if in travis CI if [ -n "${TRAVIS}" ]; then destroy_test_environment "$TEST_NAME" @@ -36,7 +31,7 @@ global_teardown() { @test "UPD025: Updating a system using a slow server" { - run sudo sh -c "$SWUPD update $SWUPD_OPTS_HTTP" + run sudo sh -c "$SWUPD update $SWUPD_OPTS" assert_status_is 0 expected_output=$(cat <<-EOM