@@ -15,6 +15,7 @@ func testInterpolatedLine(t *testing.T, expectedLine, interpolatedLine string, e
15
15
return envVariables [s ]
16
16
})
17
17
18
+ fmt .Printf ("EXPECTED: %s and ACTUAL: %s\n " , expectedLine , interpolatedLine )
18
19
assert .Equal (t , expectedLine , interpolatedLine )
19
20
}
20
21
@@ -26,10 +27,25 @@ func testInvalidInterpolatedLine(t *testing.T, line string) {
26
27
assert .Equal (t , false , success )
27
28
}
28
29
29
- func testInterpolatedDefault (t * testing.T , line string , delim string , expectedVar string , expectedVal string ) {
30
- envVar , _ := parseLine (line , func (env string ) string { return env })
30
+ func testInterpolatedDefault (t * testing.T , line string , delim string , expectedVar string , expectedVal string , envVariables map [string ]string ) {
31
+ envVar , _ := parseLine (line , func (s string ) string {
32
+ fmt .Printf ("request: %v\n " , s )
33
+ if val , ok := envVariables [s ]; ok {
34
+ return val
35
+ }
36
+ return s
37
+ })
38
+
31
39
pos := strings .Index (line , delim )
32
- envDefault , _ , _ := parseDefaultValue (line , pos )
40
+ envDefault , _ , _ := parseDefaultValue (line , pos , func (s string ) string {
41
+ fmt .Printf ("request: %v\n " , s )
42
+ if val , ok := envVariables [s ]; ok {
43
+ return val
44
+ }
45
+ return s
46
+ })
47
+ fmt .Printf ("EXPECTED: %s and ACTUAL: %s\n " , expectedVal , envDefault )
48
+ fmt .Printf ("EXPECTED: %s and ACTUAL: %s\n " , expectedVar , envVar )
33
49
assert .Equal (t , expectedVal , envDefault )
34
50
assert .Equal (t , expectedVar , envVar )
35
51
}
@@ -45,16 +61,25 @@ func TestParseLine(t *testing.T) {
45
61
"9aNumber" : "WORKED" ,
46
62
"a9Number" : "WORKED" ,
47
63
"defTest" : "WORKED" ,
64
+ "test_domain" : "127.0.0.1:27017" ,
65
+ "HOME" : "/home/foo" ,
66
+ "test_tilde" : "~/.home/test" ,
48
67
}
49
68
50
- testInterpolatedDefault (t , "${defVar:-defVal}" , ":-" , "defVar" , "defVal" )
51
- testInterpolatedDefault (t , "${defVar2-defVal2}" , "-" , "defVar2" , "defVal2" )
52
- testInterpolatedDefault (t , "${defVar:-def:Val}" , ":-" , "defVar" , "def:Val" )
53
- testInterpolatedDefault (t , "${defVar:-def-Val}" , ":-" , "defVar" , "def-Val" )
69
+ testInterpolatedDefault (t , "${defVar:-defVal}" , ":-" , "defVar" , "defVal" , variables )
70
+ testInterpolatedDefault (t , "${defVar2-defVal2}" , "-" , "defVar2" , "defVal2" , variables )
71
+ testInterpolatedDefault (t , "${defVar:-def:Val}" , ":-" , "defVar" , "def:Val" , variables )
72
+ testInterpolatedDefault (t , "${defVar:-def-Val}" , ":-" , "defVar" , "def-Val" , variables )
73
+ testInterpolatedDefault (t , "${defVar:-~/foo/bar}" , ":-" , "defVar" , "~/foo/bar" , variables )
74
+ testInterpolatedDefault (t , "${defVar:-${HOME}/.bar/test}" , ":-" , "defVar" , "/home/foo/.bar/test" , variables )
75
+ testInterpolatedDefault (t , "${defVar:-127.0.0.1:27017}" , ":-" , "defVar" , "127.0.0.1:27017" , variables )
54
76
55
77
testInterpolatedLine (t , "WORKED" , "$lower" , variables )
56
78
testInterpolatedLine (t , "WORKED" , "${MiXeD}" , variables )
57
79
testInterpolatedLine (t , "WORKED" , "${split_VaLue}" , variables )
80
+ testInterpolatedLine (t , "127.0.0.1:27017" , "${test_domain}" , variables )
81
+ testInterpolatedLine (t , "~/.home/test" , "${test_tilde}" , variables )
82
+ testInterpolatedLine (t , "~/.home/test" , "${test_tilde}" , variables )
58
83
// make sure variable name is parsed correctly with default value
59
84
testInterpolatedLine (t , "WORKED" , "${defTest:-sometest}" , variables )
60
85
testInterpolatedLine (t , "WORKED" , "${defTest-sometest}" , variables )
@@ -190,6 +215,8 @@ func TestInterpolate(t *testing.T) {
190
215
# dictionary item value
191
216
labels:
192
217
mylabel: "myvalue=="
218
+ domainlable: "127.0.0.1:27017"
219
+ tildelabel: "~/.home/test"
193
220
194
221
# unset value
195
222
hostname: "host-"
@@ -207,6 +234,8 @@ func TestInterpolate(t *testing.T) {
207
234
# dictionary item value
208
235
labels:
209
236
mylabel: "${LABEL_VALUE}"
237
+ domainlable: "${TEST_DOMAIN}"
238
+ tildelabel: "${TILDE_DIR}"
210
239
211
240
# unset value
212
241
hostname: "host-${UNSET_VALUE}"
@@ -215,6 +244,8 @@ func TestInterpolate(t *testing.T) {
215
244
command: "$${ESCAPED}"` , map [string ]string {
216
245
"IMAGE" : "=busybox" ,
217
246
"HOST_PORT" : "=" ,
247
+ "TEST_DOMAIN" : "127.0.0.1:27017" ,
248
+ "TILDE_DIR" : "~/.home/test" ,
218
249
"LABEL_VALUE" : "myvalue==" ,
219
250
})
220
251
// same as above but with default values
0 commit comments