github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/jobspec/utils_test.go (about) 1 package jobspec 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 // TestFlattenMapSlice asserts flattenMapSlice recursively flattens a slice of maps into a 10 // single map. 11 func TestFlattenMapSlice(t *testing.T) { 12 t.Parallel() 13 14 input := map[string]interface{}{ 15 "foo": 123, 16 "bar": []map[string]interface{}{ 17 { 18 "baz": 456, 19 }, 20 { 21 "baz": 789, 22 }, 23 { 24 "baax": true, 25 }, 26 }, 27 "nil": nil, 28 } 29 30 output := map[string]interface{}{ 31 "foo": 123, 32 "bar": map[string]interface{}{ 33 "baz": 789, 34 "baax": true, 35 }, 36 "nil": nil, 37 } 38 39 require.Equal(t, output, flattenMapSlice(input)) 40 41 }