storage/yaml_test.go

52 lines
1.1 KiB
Go

package storage
import (
"fmt"
"testing"
)
func TestKeysDFS(t *testing.T) {
cases := map[string]struct {
input map[string]interface{}
want [][]string
}{
"empty": {
input: map[string]interface{}{},
want: [][]string{},
},
"top level non map keys": {
input: map[string]interface{}{"a": "b", "c": "d"},
want: [][]string{},
},
"top level non map keys and map key": {
input: map[string]interface{}{"a": "b", "c": "d", "e": map[string]interface{}{"f": "g"}},
want: [][]string{[]string{"e"}},
},
"top level non map keys and map key and nested, ignore empty nested": {
input: map[string]interface{}{
"a": "b",
"c": "d",
"e": map[string]interface{}{
"f": map[string]interface{}{"g": "h"},
},
"i": map[string]interface{}{},
"j": map[string]interface{}{"k": "l"},
},
want: [][]string{[]string{"e", "f"}, []string{"j"}},
},
}
for name, d := range cases {
c := d
t.Run(name, func(t *testing.T) {
got, err := keysDFS(c.input)
if err != nil {
t.Fatal(err)
}
if fmt.Sprintf("%+v", got) != fmt.Sprintf("%+v", c.want) {
t.Fatalf("want: %+v\ngot: %+v", c.want, got)
}
})
}
}