diff options
Diffstat (limited to 'pkg/config/merge_test.go')
| -rw-r--r-- | pkg/config/merge_test.go | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/pkg/config/merge_test.go b/pkg/config/merge_test.go index c5a45754e..6785534f1 100644 --- a/pkg/config/merge_test.go +++ b/pkg/config/merge_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/syzkaller/pkg/config" ) -func TestMergeJSONData(t *testing.T) { +func TestMergeJSONs(t *testing.T) { tests := []struct { left string right string @@ -38,7 +38,52 @@ func TestMergeJSONData(t *testing.T) { }, } for _, test := range tests { - res, err := config.MergeJSONData([]byte(test.left), []byte(test.right)) + res, err := config.MergeJSONs([]byte(test.left), []byte(test.right)) + if err != nil { + t.Errorf("unexpected error: %s", err) + } + if !bytes.Equal(res, []byte(test.result)) { + t.Errorf("expected %s, got %s", test.result, res) + } + } +} + +func TestPatchJSON(t *testing.T) { + tests := []struct { + left string + patch map[string]interface{} + result string + }{ + { + `{"a":1,"b":2}`, + map[string]interface{}{"b": "string val"}, + `{"a":1,"b":"string val"}`, + }, + { + `{"a":1,"b":2}`, + map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 5, + }, + }, + }, + `{"a":{"b":{"c":5}},"b":2}`, + }, + { + `{}`, + map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 0, + }, + }, + }, + `{"a":{"b":{"c":0}}}`, + }, + } + for _, test := range tests { + res, err := config.PatchJSON([]byte(test.left), test.patch) if err != nil { t.Errorf("unexpected error: %s", err) } |
