Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 776f8c9

Browse files
William Douglasbryteise
authored andcommitted
Update use bats setup and teardown features
Instead of relying on a custom global_setup and global_teardown functions, migrate to the use of bats' setup_file and teardown_file functions. Signed-off-by: William Douglas <[email protected]>
1 parent eddf0dc commit 776f8c9

File tree

62 files changed

+431
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+431
-125
lines changed

test/functional/3rd-party/3rd-party-allow-http.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111
create_third_party_repo "$TEST_NAME" 10 staging my_repo
@@ -16,6 +16,12 @@ global_setup() {
1616

1717
}
1818

19+
teardown_file() {
20+
21+
destroy_test_environment --force "$TEST_NAME"
22+
23+
}
24+
1925
test_teardown() {
2026

2127
sudo rm -rf "$TARGET_DIR"/etc/swupd

test/functional/3rd-party/3rd-party-bundle-info-basic.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111
create_bundle -n test-bundle-upstream -f /file_upstream "$TEST_NAME"
@@ -26,6 +26,12 @@ global_setup() {
2626

2727
}
2828

29+
teardown_file() {
30+
31+
destroy_test_environment --force "$TEST_NAME"
32+
33+
}
34+
2935
@test "TPR031: Show info about a 3rd-party bundle installed in the system" {
3036

3137
run sudo sh -c "$SWUPD 3rd-party bundle-info $SWUPD_OPTS test-bundle2"

test/functional/3rd-party/3rd-party-bundle-list-basic.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111
create_bundle -n test-bundle-upstream -f /file_upstream "$TEST_NAME"
@@ -21,6 +21,12 @@ global_setup() {
2121

2222
}
2323

24+
teardown_file() {
25+
26+
destroy_test_environment --force "$TEST_NAME"
27+
28+
}
29+
2430
@test "TPR018: List installed 3rd-party bundles" {
2531

2632
# When a user list 3rd-party bundles without specifiying a repo, all

test/functional/3rd-party/3rd-party-bundle-list-deps.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111

@@ -22,6 +22,12 @@ global_setup() {
2222

2323
}
2424

25+
teardown_file() {
26+
27+
destroy_test_environment --force "$TEST_NAME"
28+
29+
}
30+
2531
@test "TPR020: List dependencies of a 3rd-party bundle" {
2632

2733
run sudo sh -c "$SWUPD 3rd-party bundle-list $SWUPD_OPTS --deps test-bundle2"

test/functional/3rd-party/3rd-party-bundle-list-orphans.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME" 10 1
1111
create_third_party_repo -a "$TEST_NAME" 10 1 repo1
@@ -20,6 +20,12 @@ global_setup() {
2020

2121
}
2222

23+
teardown_file() {
24+
25+
destroy_test_environment --force "$TEST_NAME"
26+
27+
}
28+
2329
@test "TPR093: List orphaned 3rd-party bundles" {
2430

2531
run sudo sh -c "$SWUPD 3rd-party bundle-list $SWUPD_OPTS --orphans"

test/functional/3rd-party/3rd-party-check-update-basic.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111

@@ -20,6 +20,12 @@ global_setup() {
2020

2121
}
2222

23+
teardown_file() {
24+
25+
destroy_test_environment --force "$TEST_NAME"
26+
27+
}
28+
2329
@test "TPR053: Check for available updates on third party repos" {
2430

2531
run sudo sh -c "$SWUPD 3rd-party check-update $SWUPD_OPTS"

test/functional/3rd-party/3rd-party-diagnose-basic.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME" 10 1
1111

@@ -32,6 +32,12 @@ global_setup() {
3232

3333
}
3434

35+
teardown_file() {
36+
37+
destroy_test_environment --force "$TEST_NAME"
38+
39+
}
40+
3541
@test "TPR042: Diagnose shows modified files, new files and deleted files from 3rd-party bundles" {
3642

3743
run sudo sh -c "$SWUPD 3rd-party diagnose $SWUPD_OPTS"

test/functional/3rd-party/3rd-party-json-output-multirepo.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111

@@ -16,6 +16,12 @@ global_setup() {
1616

1717
}
1818

19+
teardown_file() {
20+
21+
destroy_test_environment --force "$TEST_NAME"
22+
23+
}
24+
1925
@test "TPR089: Using the --json-output flag with functions that run in multiple repos specifying a repo" {
2026

2127
run sudo sh -c "$SWUPD 3rd-party bundle-list $SWUPD_OPTS --json-output --repo repo1"

test/functional/3rd-party/3rd-party-repo-add-negative.bats

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55

66
load "../testlib"
77

8-
global_setup() {
8+
setup_file() {
99

1010
create_test_environment "$TEST_NAME"
1111
create_third_party_repo "$TEST_NAME" 10 staging test-repo1
1212

1313
}
1414

15+
teardown_file() {
16+
17+
destroy_test_environment --force "$TEST_NAME"
18+
19+
}
20+
1521
@test "TPR003: Negative test, repo add usage" {
1622

1723
run sudo sh -c "$SWUPD 3rd-party add $SWUPD_OPTS"

test/functional/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A new test script will be generated in the current directory.
4343

4444
load "../testlib"
4545

46-
global_setup() {
46+
setup_file() {
4747

4848
# global setup
4949

@@ -61,7 +61,7 @@ test_teardown() {
6161
# destroy_test_environment "$TEST_NAME"
6262
}
6363

64-
global_teardown() {
64+
teardown_file() {
6565

6666
# global cleanup
6767

@@ -83,7 +83,7 @@ global_teardown() {
8383
}
8484
```
8585

86-
4. The global_setup() function contains commands that are run only once per test
86+
4. The setup_file() function contains commands that are run only once per test
8787
script, it runs before any test in the script is executed.
8888

8989
5. The test_setup() function contains commands that should be executed before every
@@ -106,7 +106,7 @@ if this is the case you can go ahead and remove the local test_teardown definiti
106106
test script so the pre-defined one is used, if you have more specific cleanup needs you will
107107
need to overwrite the function.
108108

109-
7. The global_teardown() function contains commands that are run only once per test
109+
7. The teardown_file() function contains commands that are run only once per test
110110
script, it runs once all tests in the scripts have finished.
111111

112112
8. Every test within the test file starts with the @test identifier followed

0 commit comments

Comments
 (0)