forked from gruntwork-io/bash-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.bats
195 lines (157 loc) · 4.93 KB
/
assert.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bats
source "$BATS_TEST_DIRNAME/../modules/bash-commons/src/assert.sh"
load "test-helper"
@test "assert_is_installed on bash built in" {
run assert_is_installed "echo"
assert_success
}
@test "assert_is_installed on installed app" {
run assert_is_installed "bats"
assert_success
}
@test "assert_is_installed on non-existent app" {
run assert_is_installed "not-a-real-app"
assert_failure
}
@test "assert_not_empty on empty string" {
run assert_not_empty "--foo"
assert_failure
}
@test "assert_not_empty on non-empty string" {
run assert_not_empty "--foo" "bar"
assert_success
}
@test "assert_not_empty on null string" {
run assert_not_empty "--foo" "null"
assert_success
}
@test "assert_not_empty on empty array" {
local empty=()
run assert_not_empty "--foo" "${empty[@]}"
assert_failure
}
@test "assert_not_empty on non-empty array" {
local non_empty=("foo" "bar" "baz")
run assert_not_empty "--foo" "${non_empty[@]}"
assert_success
}
@test "assert_empty on empty string" {
run assert_empty "--foo"
assert_success
}
@test "assert_empty on non-empty string" {
run assert_empty "--foo" "bar"
assert_failure
}
@test "assert_empty on empty array" {
local empty=()
run assert_empty "--foo" "${empty[@]}"
assert_success
}
@test "assert_empty on non-empty array" {
local non_empty=("foo" "bar" "baz")
run assert_empty "--foo" "${non_empty[@]}"
assert_failure
}
@test "assert_not_empty_or_null on empty string" {
run assert_not_empty_or_null
assert_failure
}
@test "assert_not_empty_or_null on non-empty string" {
run assert_not_empty_or_null "bar"
assert_success
}
@test "assert_not_empty_or_null on null string" {
run assert_not_empty_or_null "null"
assert_failure
}
@test "assert_not_empty_or_null on empty array" {
local readonly empty=()
run assert_not_empty_or_null "${empty[@]}"
assert_failure
}
@test "assert_not_empty_or_null on non-empty array" {
local readonly non_empty=("foo" "bar" "baz")
run assert_not_empty_or_null "${non_empty[@]}"
assert_success
}
@test "assert_value_in_list empty list" {
run assert_value_in_list "--foo" "foo"
assert_failure
}
@test "assert_value_in_list list of length 1, no match" {
run assert_value_in_list "--foo" "foo" "bar"
assert_failure
}
@test "assert_value_in_list list of length 3, no match" {
run assert_value_in_list "--foo" "foo" "bar" "baz" "blah"
assert_failure
}
@test "assert_value_in_list list of length 1, match" {
run assert_value_in_list "--foo" "foo" "foo"
assert_success
}
@test "assert_value_in_list list of length 3, match" {
run assert_value_in_list "--foo" "foo" "bar" "baz" "foo"
assert_success
}
@test "assert_value_in_list list of length 3, with spaces in the values, no match" {
run assert_value_in_list "--foo" "foo" "foo bar" "baz blah"
assert_failure
}
@test "assert_exactly_one_of list of length 2, with value in pos 1" {
run assert_exactly_one_of "--foo" "foo" "--bar" ""
assert_success
}
@test "assert_exactly_one_of list of length 2, with value in pos 2" {
run assert_exactly_one_of "--foo" "" "--bar" "bar"
assert_success
}
@test "assert_exactly_one_of list of length 3, with value in pos 1" {
run assert_exactly_one_of "--foo" "foo" "--bar" "" "--baz" ""
assert_success
}
@test "assert_exactly_one_of list of length 3, with value in pos 2" {
run assert_exactly_one_of "--foo" "" "--bar" "bar" "--baz" ""
assert_success
}
@test "assert_exactly_one_of list of length 3, with value in pos 3" {
run assert_exactly_one_of "--foo" "" "--bar" "" "--baz" "baz"
assert_success
}
@test "assert_exactly_one_of list of length 3, with value in pos 1 and 2" {
run assert_exactly_one_of "--foo" "foo" "--bar" "bar" "--baz" ""
assert_failure
}
@test "assert_exactly_one_of list of length 3, with value in pos 1 and 3" {
run assert_exactly_one_of "--foo" "foo" "--bar" "" "--baz" "baz"
assert_failure
}
@test "assert_exactly_one_of list of length 3, with value in pos 2 and 3" {
run assert_exactly_one_of "--foo" "" "--bar" "bar" "--baz" "baz"
assert_failure
}
@test "assert_exactly_one_of list of length 3, with value in pos 1, 2 and 3" {
run assert_exactly_one_of "--foo" "foo" "--bar" "bar" "--baz" "baz"
assert_failure
}
@test "assert_exactly_one_of list of length 4, with value in pos 2" {
run assert_exactly_one_of "--foo" "" "--bar" "bar" "--baz" "" "--qux" ""
assert_success
}
@test "assert_exactly_one_of list of length 4, with value in pos 2 and 4" {
run assert_exactly_one_of "--foo" "" "--bar" "bar" "--baz" "" "--qux" "qux"
assert_failure
}
@test "assert_exactly_one_of list of length 4, with no value set" {
run assert_exactly_one_of "--foo" "" "--bar" "" "--baz" "" "--qux" ""
assert_failure
}
@test "assert_exactly_one_of list of length 5, with one value set, fails for odd num_args" {
run assert_exactly_one_of "--foo" "foo" "--bar" "" "--baz" "" "--qux"
assert_failure
}
@test "assert_uid_is_root_or_sudo as root" {
run assert_uid_is_root_or_sudo
assert_success
}