Skip to content

Commit

Permalink
Add functional tests for RFC6902 spec. Appendix A1
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Rutkowski <[email protected]>
  • Loading branch information
mrutkows committed Jan 16, 2024
1 parent fa14eb8 commit 369479a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmd/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,20 @@ func addValue(parentMap map[string]interface{}, keys []string, value interface{}
if lengthKeys == 0 {
return fmt.Errorf("invalid map key (nil)")
}
nextNodeKey := keys[0]
nextNode := parentMap[nextNodeKey]

// if lengthKeys
var nextNodeKey string // := keys[0]
var nextNode interface{} // := parentMap[nextNodeKey]

switch lengthKeys {
case 0:
return fmt.Errorf("invalid map key (nil)")
case 1: // special case of adding new key/value to document root
nextNode = parentMap
default: // adding keys/values along document path
nextNodeKey := keys[0]
nextNode = parentMap[nextNodeKey]
}

switch typedNode := nextNode.(type) {
case map[string]interface{}:
Expand Down
16 changes: 16 additions & 0 deletions cmd/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ func TestPatchCdx15SliceAdd(t *testing.T) {
getLogger().Tracef("%s\n", buffer.String())
}

func TestPatchRFC6902AppendixA1Patch1(t *testing.T) {
ti := NewPatchTestInfo(
TEST_PATCH_RFC_6902_APPX_A_1_BASE,
TEST_PATCH_RFC_6902_APPX_A_1_PATCH_1, nil)
ti.IsInputJSON = true
buffer, _, err := innerTestPatch(t, ti)
if err != nil {
t.Error(err)
}
getLogger().Tracef("%s\n", buffer.String())
// lineNum, _ := bufferLineContainsValues(buffer, -1, "qux")
// if lineNum != 3 {
// t.Errorf("invalid output. Expected added value: \"qux\" at line: 3")
// }
}

func TestPatchRFC6902AppendixA2Patch1(t *testing.T) {
ti := NewPatchTestInfo(
TEST_PATCH_RFC_6902_APPX_A_2_BASE,
Expand Down

0 comments on commit 369479a

Please sign in to comment.