Skip to content

Commit 690442d

Browse files
committed
Handles keys that dont exit
1 parent d1c545c commit 690442d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

data_navigator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func recurse(value interface{}, head string, tail []string) interface{} {
3030
log.Fatalf("Error accessing array: %v", err)
3131
}
3232
return readArray(value.([]interface{}), index, tail)
33+
case nil:
34+
return nil
3335
default:
3436
return readMap(value.(map[interface{}]interface{}), head, tail)
3537
}

data_navigator_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ func TestReadMap_simple(t *testing.T) {
3131
assertResult(t, 2, readMap(parsedData, "b", []string{"c"}))
3232
}
3333

34-
func TestReadMap_array(t *testing.T) {
34+
func TestReadMap_key_doesnt_exist(t *testing.T) {
35+
assertResult(t, nil, readMap(parsedData, "b.x.f", []string{"c"}))
36+
}
37+
38+
func TestReadMap_with_array(t *testing.T) {
3539
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
3640
}
3741

38-
func TestReadMap_array_out_of_bounds(t *testing.T) {
42+
func TestReadMap_with_array_out_of_bounds(t *testing.T) {
3943
assertResult(t, nil, readMap(parsedData, "b", []string{"d", "3"}))
4044
}
4145

0 commit comments

Comments
 (0)