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 <castulo.martinez@intel.com>
This commit is contained in:
Castulo Martinez
2018-12-10 21:13:03 +00:00
committed by Otavio Pontes
parent 8ed78a3758
commit d97234ff6b
2 changed files with 11 additions and 21 deletions
@@ -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
+6 -11
View File
@@ -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