yaml namespaces
This commit is contained in:
51
yaml_test.go
Normal file
51
yaml_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user