Skip to content

Commit 558b422

Browse files
committed
feat(interpolate): Add cast to bool for 'depends_on' required and restart options
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent 75fb1ab commit 558b422

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

interpolation/interpolation_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import (
2727
)
2828

2929
var defaults = map[string]string{
30-
"USER": "jenny",
31-
"FOO": "bar",
32-
"count": "5",
30+
"USER": "jenny",
31+
"FOO": "bar",
32+
"count": "5",
33+
"REQUIRED": "true",
3334
}
3435

3536
func defaultMapping(name string) (string, bool) {
@@ -196,19 +197,27 @@ func TestInterpolateWithCast(t *testing.T) {
196197
config := map[string]interface{}{
197198
"foo": map[string]interface{}{
198199
"replicas": "$count",
200+
"required": "$REQUIRED",
199201
},
200202
}
201203
toInt := func(value string) (interface{}, error) {
202204
return strconv.Atoi(value)
203205
}
206+
toBoolean := func(value string) (interface{}, error) {
207+
return strconv.ParseBool(value)
208+
}
204209
result, err := Interpolate(config, Options{
205-
LookupValue: defaultMapping,
206-
TypeCastMapping: map[tree.Path]Cast{tree.NewPath(tree.PathMatchAll, "replicas"): toInt},
210+
LookupValue: defaultMapping,
211+
TypeCastMapping: map[tree.Path]Cast{
212+
tree.NewPath(tree.PathMatchAll, "replicas"): toInt,
213+
tree.NewPath(tree.PathMatchAll, "required"): toBoolean,
214+
},
207215
})
208216
assert.NilError(t, err)
209217
expected := map[string]interface{}{
210218
"foo": map[string]interface{}{
211219
"replicas": 5,
220+
"required": true,
212221
},
213222
}
214223
assert.Check(t, is.DeepEqual(expected, result))

loader/interpolate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var interpolateTypeCastMapping = map[tree.Path]interp.Cast{
3636
servicePath("cpus"): toFloat32,
3737
servicePath("cpu_shares"): toInt64,
3838
servicePath("init"): toBoolean,
39+
servicePath("depends_on", tree.PathMatchAll, "required"): toBoolean,
40+
servicePath("depends_on", tree.PathMatchAll, "restart"): toBoolean,
3941
servicePath("deploy", "replicas"): toInt,
4042
servicePath("deploy", "update_config", "parallelism"): toInt,
4143
servicePath("deploy", "update_config", "max_failure_ratio"): toFloat,

0 commit comments

Comments
 (0)