github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/types/parameters/parameters_test.go (about) 1 package parameters 2 3 import ( 4 "testing" 5 6 "gotest.tools/assert" 7 is "gotest.tools/assert/cmp" 8 ) 9 10 func TestFromFlattenError(t *testing.T) { 11 _, err := FromFlatten(map[string]string{ 12 "foo": "bar", 13 "foo.baz": "biz", 14 }) 15 // Can't have a sub-value (foo.baz) of an existing value (foo) 16 assert.Check(t, err != nil) 17 18 _, err = FromFlatten(map[string]string{ 19 "foo": "bar", 20 "foo.0": "biz", 21 }) 22 // Can't have an array value (foo.0) of an existing value (foo) 23 assert.Check(t, err != nil) 24 25 _, err = FromFlatten(map[string]string{ 26 "foo.0": "bar", 27 "foo.baz": "biz", 28 }) 29 // Can't have an array value (foo.0) and a sub-value (foo.baz) at the same time 30 assert.Check(t, err != nil) 31 } 32 33 func TestFromFlatten(t *testing.T) { 34 s, err := FromFlatten(map[string]string{ 35 "foo": "bar", 36 "bar.baz": "banana", 37 "bar.port": "80", 38 "baz.biz.a": "1", 39 "baz.biz.b": "2", 40 "baz.boz": "buz", 41 "toto.0": "a", 42 "toto.1": "b", 43 "toto.3": "d", 44 "boolean": "false", 45 "frog": "{bear}", 46 }) 47 assert.NilError(t, err) 48 assert.Check(t, is.DeepEqual(s, Parameters{ 49 "foo": "bar", 50 "bar": map[string]interface{}{ 51 "baz": "banana", 52 "port": 80, 53 }, 54 "baz": map[string]interface{}{ 55 "biz": map[string]interface{}{ 56 "a": 1, 57 "b": 2, 58 }, 59 "boz": "buz", 60 }, 61 "toto": []interface{}{"a", "b", nil, "d"}, 62 "boolean": false, 63 "frog": map[interface{}]interface{}{ 64 "bear": nil, 65 }, 66 })) 67 }