2019-07-30 22:40:45 +00:00
|
|
|
package jobspec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2019-07-30 22:40:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestFlattenMapSlice asserts flattenMapSlice recursively flattens a slice of maps into a
|
|
|
|
// single map.
|
|
|
|
func TestFlattenMapSlice(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2019-07-30 22:40:45 +00:00
|
|
|
|
|
|
|
input := map[string]interface{}{
|
|
|
|
"foo": 123,
|
|
|
|
"bar": []map[string]interface{}{
|
|
|
|
{
|
|
|
|
"baz": 456,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"baz": 789,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"baax": true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"nil": nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
output := map[string]interface{}{
|
|
|
|
"foo": 123,
|
|
|
|
"bar": map[string]interface{}{
|
|
|
|
"baz": 789,
|
|
|
|
"baax": true,
|
|
|
|
},
|
|
|
|
"nil": nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, output, flattenMapSlice(input))
|
|
|
|
|
|
|
|
}
|