-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsempl-test.sh
More file actions
162 lines (159 loc) · 5.01 KB
/
sempl-test.sh
File metadata and controls
162 lines (159 loc) · 5.01 KB
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
source ./sempl
describe "test private functions"
it_displays_usage() {
cmd "_usage"
assert_rc 0
assert_content "usage: "
assert_content "-h "
}
it_displays_verbose() {
cmd "__sempl_verbose=1 _verbose 'test out'"
assert_rc 0
assert_content "test out"
}
it_is_not_verbose() {
cmd "__sempl_verbose=0 _verbose 'test out'"
assert_content_not "test out"
}
it_displays_version() {
cmd "__sempl_version=1.2.3 _version"
assert_content "version 1.2.3"
}
it_displays_error() {
cmd "_error 'test error'"
assert_rc 1
assert_content "ERROR: test error"
}
describe "test cli flags"
it_errors_without_args() {
cmd "_main"
assert_rc 1
assert_content "usage: "
}
it_errors_without_template() {
cmd "_main -v"
assert_rc 1
assert_content "ERROR: "
}
it_errors_with_nonexistent_template() {
cmd "_main nosuchfile"
assert_rc 1
assert_content "ERROR: "
}
it_converts_template() {
cmd "_main -o ./test/fixtures/001_variable_default.tmpl"
assert_rc 0
assert_content "testvar=defaultvalue"
}
it_errors_when_varsfile_is_not_found() {
cmd "_main -o -s nosuchfile ./test/fixtures/009_varsfile.tmpl"
assert_rc 1
assert_content "ERROR: "
}
it_errors_when_varsfile_is_not_found() {
cmd "_main -o -s nosuchfile ./test/fixtures/009_varsfile.tmpl"
assert_rc 1
assert_content "ERROR: "
}
it_sources_varsfile() {
cmd "_main -o -s ./test/fixtures/varsfile.txt ./test/fixtures/009_varsfile.tmpl"
assert_rc 0
assert_content "testvar=sourcedvalue"
}
it_sources_encrypted_varsfile_from_pass() {
cmd "_main -o -p password -s ./test/fixtures/varsfile.enc ./test/fixtures/009_varsfile.tmpl"
assert_rc 0
assert_content "testvar=sourcedvalue"
}
it_sources_encrypted_varsfile_from_passfile() {
echo "password" > passfile
cmd "_main -o -k passfile -s ./test/fixtures/varsfile.enc ./test/fixtures/009_varsfile.tmpl"
assert_rc 0
assert_content "testvar=sourcedvalue"
rm passfile
}
it_sources_varsfile_with_bad_password() {
cmd "_main -o -p badpass -s ./test/fixtures/varsfile.enc ./test/fixtures/009_varsfile.tmpl"
assert_rc 1
assert_content "ERROR: "
}
describe "test template conversion"
it_converts_template_001_variable_default() {
cmd "__sempl_template=./test/fixtures/001_variable_default.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content "testvar=defaultvalue"
}
it_converts_template_002_variable_escaping() {
cmd "__sempl_template=./test/fixtures/002_variable_escaping.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content 'testvar=$testvar'
}
it_converts_template_003_variable_expansion() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/003_variable_expansion.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content 'testvar=testvalue'
}
it_converts_template_004_variable_expansion() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/004_variable_expansion.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content 'testvar=testvalue'
}
it_converts_template_005_double_quote() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/005_double_quote.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content 'testvar="testvalue"'
}
it_converts_template_006_single_quote() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/006_single_quote.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content "testvar='testvalue'"
}
it_converts_template_007_bash_inline() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/007_bash_inline.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_content 'testvar="inline"'
}
it_converts_template_008_bash_loop() {
cmd "testvar=testvalue __sempl_template=./test/fixtures/008_bash_loop.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_regex '^ 1$'
assert_regex '^ 2$'
assert_regex '^ 3$'
}
it_converts_template_010_symbol_test() {
cmd "__sempl_template=./test/fixtures/010_symbol_test.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_regex '^>test$'
assert_regex '^>test$'
assert_regex '^!test$'
assert_regex '^\\test$'
assert_regex '^#test$'
assert_regex '^\.test$'
assert_regex '^@test$'
assert_regex '^%test$'
assert_regex '^\^test$'
assert_regex '^\&test$'
assert_regex '^\*test$'
assert_regex '^\(test$'
assert_regex '^\)test$'
assert_regex '^\-test$'
assert_regex '^\+test$'
assert_regex '^\=test$'
assert_regex '^\{test$'
assert_regex '^\}test$'
assert_regex '^\|test$'
assert_regex '^\/test$'
assert_regex '^\,test$'
assert_regex '^\;test$'
assert_regex '^\:test$'
assert_regex '^\_test$'
}
it_succeeds_on_missing_var_without_fail_option() {
cmd "__sempl_template=./test/fixtures/011_variable_missing.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 0
assert_regex '^testvar=$'
}
it_fails_on_missing_var_with_fail_option() {
cmd "__sempl_fail_missing=1 __sempl_template=./test/fixtures/011_variable_missing.tmpl __sempl_outfile=/dev/stdout _convert_template"
assert_rc 1
}