Skip to content

Commit 47e4490

Browse files
committed
refactor: diff
1 parent d978456 commit 47e4490

1 file changed

Lines changed: 22 additions & 99 deletions

File tree

integration-test/namespace/test.sh

Lines changed: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,86 @@
11
#!/bin/bash
22

3-
empty_list() {
4-
output=$(../nsctl ns list)
5-
expect=$(cat empty_list.txt)
6-
7-
if [ "$output" != "$expect" ]; then
8-
echo "[-] Empty list test failed"
3+
diff() {
4+
if [ "$2" != "$3" ]; then
5+
echo "[-] $1 test failed"
96
echo "Expected:"
10-
echo "$expect"
7+
echo "$3"
118
echo "Got:"
12-
echo "$output"
9+
echo "$2"
1310
exit 1
1411
fi
1512

16-
echo "[+] Empty list test passed"
13+
echo "[+] $1 test passed"
14+
}
15+
16+
empty_list() {
17+
output=$(../nsctl ns list)
18+
expect=$(cat empty_list.txt)
19+
20+
diff "Empty list" "$output" "$expect"
1721
}
1822

1923
create_test-1() {
2024
output=$(../nsctl ns create test-1)
2125
expect=$(cat create_test-1.txt)
2226

23-
if [ "$output" != "$expect" ]; then
24-
echo "[-] Create test-1 failed"
25-
echo "Expected:"
26-
echo "$expect"
27-
echo "Got:"
28-
echo "$output"
29-
exit 1
30-
fi
31-
32-
echo "[+] Create test-1 passed"
27+
diff "Create test-1" "$output" "$expect"
3328
}
3429

3530
list_test-1() {
3631
output=$(../nsctl ns list)
3732
expect=$(cat list_test-1.txt)
3833

39-
if [ "$output" != "$expect" ]; then
40-
echo "[-] List test-1 failed"
41-
echo "Expected:"
42-
echo "$expect"
43-
echo "Got:"
44-
echo "$output"
45-
exit 1
46-
fi
47-
48-
echo "[+] List test-1 passed"
34+
diff "List test-1" "$output" "$expect"
4935
}
5036

5137
create_test-2() {
5238
output=$(../nsctl ns create test-2)
5339
expect=$(cat create_test-2.txt)
5440

55-
if [ "$output" != "$expect" ]; then
56-
echo "[-] Create test-2 failed"
57-
echo "Expected:"
58-
echo "$expect"
59-
echo "Got:"
60-
echo "$output"
61-
exit 1
62-
fi
63-
64-
echo "[+] Create test-2 passed"
41+
diff "Create test-2" "$output" "$expect"
6542
}
6643

6744
list_test-1-2() {
6845
output=$(../nsctl ns list)
6946
expect=$(cat list_test-1-2.txt)
7047

71-
if [ "$output" != "$expect" ]; then
72-
echo "[-] List test-1-2 failed"
73-
echo "Expected:"
74-
echo "$expect"
75-
echo "Got:"
76-
echo "$output"
77-
exit 1
78-
fi
79-
80-
echo "[+] List test-1-2 passed"
48+
diff "List test-1-2" "$output" "$expect"
8149
}
8250

8351
delete_test-1() {
8452
output=$(../nsctl ns delete test-1)
8553
expect=$(cat delete_test-1.txt)
8654

87-
if [ "$output" != "$expect" ]; then
88-
echo "[-] Delete test-1 failed"
89-
echo "Expected:"
90-
echo "$expect"
91-
echo "Got:"
92-
echo "$output"
93-
exit 1
94-
fi
95-
96-
echo "[+] Delete test-1 passed"
55+
diff "Delete test-1" "$output" "$expect"
9756
}
9857

9958
delete_test-1_error() {
10059
output=$(../nsctl ns delete test-1)
10160
expect=$(cat delete_test-1_error.txt)
10261

103-
if [ "$output" != "$expect" ]; then
104-
echo "[-] Delete test-1_error failed"
105-
echo "Expected:"
106-
echo "$expect"
107-
echo "Got:"
108-
echo "$output"
109-
exit 1
110-
fi
111-
112-
echo "[+] Delete test-1_error passed"
62+
diff "Delete test-1_error" "$output" "$expect"
11363
}
11464

11565
create_test-2_error() {
11666
output=$(../nsctl ns create test-2)
11767
expect=$(cat create_test-2_error.txt)
11868

119-
if [ "$output" != "$expect" ]; then
120-
echo "[-] Create test-2_error failed"
121-
echo "Expected:"
122-
echo "$expect"
123-
echo "Got:"
124-
echo "$output"
125-
exit 1
126-
fi
127-
128-
echo "[+] Create test-2_error passed"
69+
diff "Create test-2_error" "$output" "$expect"
12970
}
13071

13172
list_test-2() {
13273
output=$(../nsctl ns list)
13374
expect=$(cat list_test-2.txt)
13475

135-
if [ "$output" != "$expect" ]; then
136-
echo "[-] List test-2 failed"
137-
echo "Expected:"
138-
echo "$expect"
139-
echo "Got:"
140-
echo "$output"
141-
exit 1
142-
fi
143-
144-
echo "[+] List test-2 passed"
76+
diff "List test-2" "$output" "$expect"
14577
}
14678

14779
delete_test-2() {
14880
output=$(../nsctl ns delete test-2)
14981
expect=$(cat delete_test-2.txt)
15082

151-
if [ "$output" != "$expect" ]; then
152-
echo "[-] Delete test-2 failed"
153-
echo "Expected:"
154-
echo "$expect"
155-
echo "Got:"
156-
echo "$output"
157-
exit 1
158-
fi
159-
160-
echo "[+] Delete test-2 passed"
83+
diff "Delete test-2" "$output" "$expect"
16184
}
16285

16386
main() {

0 commit comments

Comments
 (0)