Skip to content

Commit

Permalink
Fix #560 (kinda/sorta)
Browse files Browse the repository at this point in the history
  • Loading branch information
monopole committed Nov 29, 2018
1 parent df3ec57 commit 6b93973
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pkg/transformers/mutatefield.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package transformers

import (
"fmt"
"log"
"strings"
)

type mutateFunc func(interface{}) (interface{}, error)
Expand Down Expand Up @@ -53,6 +55,11 @@ func mutateField(
v := m[pathToField[0]]
newPathToField := pathToField[1:]
switch typedV := v.(type) {
case nil:
log.Printf(
"nil value at `%s` ignored in mutation attempt",
strings.Join(pathToField, "."))
return nil
case map[string]interface{}:
return mutateField(typedV, newPathToField, createIfNotPresent, fns...)
case []interface{}:
Expand Down
7 changes: 2 additions & 5 deletions pkg/transformers/mutatefield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ func TestWithNil(t *testing.T) {
m := &noopMutator{}
err := mutateField(
obj.Map(), []string{"spec", "template", "metadata", "labels", "vegetable"}, false, m.mutate)
if err == nil {
t.Fatalf("Expected error due to nil field.")
}
if err.Error() != "<nil> is not expected to be a primitive type" {
t.Fatalf("unexpected error: %v", err)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
}

0 comments on commit 6b93973

Please sign in to comment.