diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-02-10 15:13:03 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-02-25 18:57:42 +0100 |
| commit | aa3dbd72ed6726be5bf1bec14a2ceaca369a8063 (patch) | |
| tree | a9d05b9e5b20fc512c4f0b62c444302e7e496a4c /pkg/config/merge_test.go | |
| parent | dbfe5869946787d945f1e52f9a435c5284c9edd3 (diff) | |
tools/syz-testbed: don't parse configs
It's not practical to parse configs from tools/syz-testbed because it
limits the tool to using only those configuration options, which are
supported by the syzkaller version at the moment of tools/syz-testbed
compilation.
Operate with manager configs as if they were just some JSON objects.
Introduce a PatchJSON method to update their fields in a convenient way.
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) } |
