diff --git a/assets/examples/empty.yml b/assets/examples/empty.yml new file mode 100644 index 0000000..73b314f --- /dev/null +++ b/assets/examples/empty.yml @@ -0,0 +1 @@ +--- \ No newline at end of file diff --git a/pkg/v1/ytbx/common.go b/pkg/v1/ytbx/common.go index e07d478..c1b6bc3 100644 --- a/pkg/v1/ytbx/common.go +++ b/pkg/v1/ytbx/common.go @@ -37,7 +37,8 @@ const ( // GetType returns the type of the input value with a YAML specific view func GetType(value interface{}) string { switch tobj := value.(type) { - case yaml.MapSlice: + + case yaml.MapSlice, nil: return typeMap case []interface{}: diff --git a/pkg/v1/ytbx/getting_test.go b/pkg/v1/ytbx/getting_test.go index 3911f59..c3acc72 100644 --- a/pkg/v1/ytbx/getting_test.go +++ b/pkg/v1/ytbx/getting_test.go @@ -59,4 +59,10 @@ var _ = Describe("getting stuff test cases", func() { Expect(grabError(example, "/yaml/named-entry-list-using-id/id=0")).To(BeEquivalentTo("there is no entry id=0 in the list")) }) }) + Context("Trying to get values by path in an empty file", func() { + It("should return a not found key error", func() { + emptyFile := yml("../../../assets/examples/empty.yml") + Expect(grabError(emptyFile, "does-not-exist")).To(BeEquivalentTo("no key 'does-not-exist' found in map, available keys: ")) + }) + }) })