@@ -27,9 +27,10 @@ import (
2727)
2828
2929var 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
3536func 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 ))
0 commit comments