From 46e659b83e322e019b8a20d563f0258d9a8e2666 Mon Sep 17 00:00:00 2001 From: "florian.cazals" Date: Mon, 20 Nov 2023 08:51:59 +0000 Subject: [PATCH] feat(venom): add ShouldJSONContain and ShouldJSONContainWithKey and negations (#746) Signed-off-by: florian.cazals --- README.md | 4 + assertions/assertions.go | 106 ++++ assertions/assertions_test.go | 556 ++++++++++++++++++ tests/assertions/ShouldJSONContain.yml | 21 + tests/assertions/ShouldJSONContainWithKey.yml | 31 + tests/assertions/ShouldNotJSONContain.yml | 20 + .../ShouldNotJSONContainWithKey.yml | 28 + 7 files changed, 766 insertions(+) create mode 100644 tests/assertions/ShouldJSONContain.yml create mode 100644 tests/assertions/ShouldJSONContainWithKey.yml create mode 100644 tests/assertions/ShouldNotJSONContain.yml create mode 100644 tests/assertions/ShouldNotJSONContainWithKey.yml diff --git a/README.md b/README.md index 9c421e49..d3e32da0 100644 --- a/README.md +++ b/README.md @@ -636,6 +636,10 @@ The value `this-value-is-secret` will not be printed in your console, `venom.log * ShouldNotBeBetweenOrEqual - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldNotBeBetweenOrEqual.yml) * ShouldContain - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldContain.yml) * ShouldNotContain - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldNotContain.yml) +* ShouldJSONContain - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldJSONContain.yml) +* ShouldNotJSONContain - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldNotJSONContain.yml) +* ShouldJSONContainWithKey - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldJSONContainWithKey.yml) +* ShouldNotJSONContainWithKey - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldNotJSONContainWithKey.yml) * ShouldContainKey - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldContainKey.yml) * ShouldNotContainKey - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldNotContainKey.yml) * ShouldBeIn - [example](https://github.com/ovh/venom/tree/master/tests/assertions/ShouldBeIn.yml) diff --git a/assertions/assertions.go b/assertions/assertions.go index f4ed2fcf..184e3240 100644 --- a/assertions/assertions.go +++ b/assertions/assertions.go @@ -38,6 +38,10 @@ var assertMap = map[string]AssertFunc{ "ShouldNotBeBetweenOrEqual": ShouldNotBeBetweenOrEqual, "ShouldContain": ShouldContain, "ShouldNotContain": ShouldNotContain, + "ShouldJSONContain": ShouldJSONContain, + "ShouldNotJSONContain": ShouldNotJSONContain, + "ShouldJSONContainWithKey": ShouldJSONContainWithKey, + "ShouldNotJSONContainWithKey": ShouldNotJSONContainWithKey, "ShouldContainKey": ShouldContainKey, "ShouldNotContainKey": ShouldNotContainKey, "ShouldBeIn": ShouldBeIn, @@ -608,6 +612,108 @@ func ShouldNotContain(actual interface{}, expected ...interface{}) error { return nil } +// ShouldJSONContain receives exactly two parameters. The first is a slice, the +// second is a proposed JSON member. +// Equality is determined using ShouldJSONEqual. +func ShouldJSONContain(actual interface{}, expected ...interface{}) error { + if err := need(1, expected); err != nil { + return err + } + actualSlice, err := cast.ToSliceE(actual) + if err != nil { + return err + } + for i := range actualSlice { + if ShouldJSONEqual(actualSlice[i], expected[0]) == nil { + return nil + } + } + return fmt.Errorf("expected '%v' to contain %v but it wasnt", actual, expected[0]) +} + +// ShouldNotJSONContain receives exactly two parameters. The first is a slice, the +// second is a proposed JSON member. +// Equality is determined using ShouldJSONEqual. +func ShouldNotJSONContain(actual interface{}, expected ...interface{}) error { + if err := need(1, expected); err != nil { + return err + } + actualSlice, err := cast.ToSliceE(actual) + if err != nil { + return err + } + for i := range actualSlice { + if ShouldJSONEqual(actualSlice[i], expected[0]) == nil { + return fmt.Errorf("expected '%v' not contain %v but it was", actual, expected[0]) + } + } + return nil +} + +// ShouldJSONContainWithKey receives exactly three parameters. The first is a slice, the +// second is a key in the inner slice structure and the third is a proposed value associated to the key. +// Equality is determined using ShouldJSONEqual. +func ShouldJSONContainWithKey(actual interface{}, expected ...interface{}) error { + if err := need(2, expected); err != nil { + return err + } + actualSlice, err := cast.ToSliceE(actual) + if err != nil { + return err + } + if reflect.TypeOf(expected[0]).Kind() != reflect.String { + return fmt.Errorf("expected '%v' to be a string", expected[0]) + } + expectedKey := cast.ToString(expected[0]) + for i := range actualSlice { + if reflect.TypeOf(actualSlice[i]).Kind() != reflect.Map && reflect.TypeOf(actualSlice[i]).Kind() != reflect.Struct { + return fmt.Errorf("expected '%v' to be a map or a struct", actualSlice[i]) + } + elem := cast.ToStringMap(actualSlice[i]) + if err != nil { + return err + } + if _, ok := elem[expectedKey]; ok { + if ShouldJSONEqual(elem[expectedKey], expected[1]) == nil { + return nil + } + } + } + return fmt.Errorf("expected '%v' contain a key '%s' with value %v but it wasnt", actual, expectedKey, expected[1]) +} + +// ShouldNotJSONContainWithKey receives exactly three parameters. The first is a slice, the +// second is a key in the inner slice structure and the third is a proposed value associated to the key. +// Equality is determined using ShouldJSONEqual. +func ShouldNotJSONContainWithKey(actual interface{}, expected ...interface{}) error { + if err := need(2, expected); err != nil { + return err + } + actualSlice, err := cast.ToSliceE(actual) + if err != nil { + return err + } + if reflect.TypeOf(expected[0]).Kind() != reflect.String { + return fmt.Errorf("expected '%v' to be a string", expected[0]) + } + expectedKey := cast.ToString(expected[0]) + for i := range actualSlice { + if reflect.TypeOf(actualSlice[i]).Kind() != reflect.Map && reflect.TypeOf(actualSlice[i]).Kind() != reflect.Struct { + return fmt.Errorf("expected '%v' to be a map or a struct currently %v", actualSlice[i], reflect.TypeOf(actualSlice[i]).Kind()) + } + elem := cast.ToStringMap(actualSlice[i]) + if err != nil { + return err + } + if _, ok := elem[expectedKey]; ok { + if ShouldJSONEqual(elem[expectedKey], expected[1]) == nil { + return fmt.Errorf("expected '%v' not contain a key '%s' with value %v but it was", actual, expectedKey, expected[1]) + } + } + } + return nil +} + // ShouldContainKey receives exactly two parameters. The first is a map and the // second is a proposed key. func ShouldContainKey(actual interface{}, expected ...interface{}) error { diff --git a/assertions/assertions_test.go b/assertions/assertions_test.go index cdba9dd6..ce35de65 100644 --- a/assertions/assertions_test.go +++ b/assertions/assertions_test.go @@ -736,6 +736,562 @@ func TestShouldNotContain(t *testing.T) { } } +func TestShouldJSONContain(t *testing.T) { + type args struct { + actual interface{} + expected []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // Objects and arrays + { + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{`{"a":1,"b":2,"c":{"x":1,"y":2}}`}, + }, + }, + { + // Spaces, newlines, tabs and key order (including in nested objects) don't matter + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{` { "c" : { "y" : 2 , "x" : 1 }, "b" : 2 ,` + "\n\t" + ` "a" : 1 } `}, + }, + }, + { + name: "array", + args: args{ + actual: []interface{}{[]interface{}{1, 2}}, + expected: []interface{}{`[1,2]`}, + }, + }, + { + // Spaces, newlines and tabs don't matter + name: "array", + args: args{ + actual: []interface{}{[]interface{}{1, 2}}, + expected: []interface{}{` [ 1 ,` + "\n\t" + ` 2 ] `}, + }, + }, + // Object and array errors + { + name: "bad value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`{"a":2}`}, + }, + wantErr: true, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`{"a":"1"}`}, + }, + wantErr: true, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2}}, + expected: []interface{}{`{"a":1}`}, + }, + wantErr: true, + }, + { + name: "bad array order", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1, 2}}}, + expected: []interface{}{`{"a":[2,1]}`}, + }, + wantErr: true, + }, + { + name: "object instead of array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`[1]`}, + }, + wantErr: true, + }, + { + name: "array instead of object", + args: args{ + actual: []interface{}{[]interface{}{1}}, + expected: []interface{}{`{"a":1}}`}, + }, + wantErr: true, + }, + // Primitive values + { + name: "string", + args: args{ + actual: []interface{}{"a"}, + expected: []interface{}{"a"}, + }, + }, + { + name: "empty string", + args: args{ + actual: []interface{}{""}, + expected: []interface{}{""}, + }, + }, + { + name: "number", + args: args{ + actual: []interface{}{json.Number("1")}, + expected: []interface{}{`1`}, + }, + }, + { + name: "number", + args: args{ + actual: []interface{}{json.Number("1.2")}, + expected: []interface{}{`1.2`}, + }, + }, + { + name: "boolean", + args: args{ + actual: []interface{}{true}, + expected: []interface{}{`true`}, + }, + }, + { + // TODO: Shouldn't be valid, but Venom currently passes an empty string to the assertion function when the JSON value is `null`. + name: "null", + args: args{ + actual: []interface{}{""}, + expected: []interface{}{`null`}, + }, + }, + // Primitive value errors + { + name: "bad value", + args: args{ + actual: []interface{}{"a"}, + expected: []interface{}{"b"}, + }, + wantErr: true, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{float64(1)}, + expected: []interface{}{"1"}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ShouldJSONContain(tt.args.actual, tt.args.expected...); (err != nil) != tt.wantErr { + t.Errorf("ShouldJSONContain() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestShouldNotJSONContain(t *testing.T) { + type args struct { + actual interface{} + expected []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // Objects and arrays + { + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{`{"a":1,"b":2,"c":{"x":1,"y":2}}`}, + }, + wantErr: true, + }, + { + // Spaces, newlines, tabs and key order (including in nested objects) don't matter + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{` { "c" : { "y" : 2 , "x" : 1 }, "b" : 2 ,` + "\n\t" + ` "a" : 1 } `}, + }, + wantErr: true, + }, + { + name: "array", + args: args{ + actual: []interface{}{[]interface{}{1, 2}}, + expected: []interface{}{`[1,2]`}, + }, + wantErr: true, + }, + { + // Spaces, newlines and tabs don't matter + name: "array", + args: args{ + actual: []interface{}{[]interface{}{1, 2}}, + expected: []interface{}{` [ 1 ,` + "\n\t" + ` 2 ] `}, + }, + wantErr: true, + }, + // Object and array errors + { + name: "bad value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`{"a":2}`}, + }, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`{"a":"1"}`}, + }, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2}}, + expected: []interface{}{`{"a":1}`}, + }, + }, + { + name: "bad array order", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1, 2}}}, + expected: []interface{}{`{"a":[2,1]}`}, + }, + }, + { + name: "object instead of array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`[1]`}, + }, + }, + { + name: "array instead of object", + args: args{ + actual: []interface{}{[]interface{}{1}}, + expected: []interface{}{`{"a":1}}`}, + }, + }, + // Primitive values + { + name: "string", + args: args{ + actual: []interface{}{"a"}, + expected: []interface{}{"a"}, + }, + wantErr: true, + }, + { + name: "empty string", + args: args{ + actual: []interface{}{""}, + expected: []interface{}{""}, + }, + wantErr: true, + }, + { + name: "number", + args: args{ + actual: []interface{}{json.Number("1")}, + expected: []interface{}{`1`}, + }, + wantErr: true, + }, + { + name: "number", + args: args{ + actual: []interface{}{json.Number("1.2")}, + expected: []interface{}{`1.2`}, + }, + wantErr: true, + }, + { + name: "boolean", + args: args{ + actual: []interface{}{true}, + expected: []interface{}{`true`}, + }, + wantErr: true, + }, + { + // TODO: Shouldn't be valid, but Venom currently passes an empty string to the assertion function when the JSON value is `null`. + name: "null", + args: args{ + actual: []interface{}{""}, + expected: []interface{}{`null`}, + }, + wantErr: true, + }, + // Primitive value errors + { + name: "bad value", + args: args{ + actual: []interface{}{"a"}, + expected: []interface{}{"b"}, + }, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{float64(1)}, + expected: []interface{}{"1"}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ShouldNotJSONContain(tt.args.actual, tt.args.expected...); (err != nil) != tt.wantErr { + t.Errorf("ShouldNotJSONContain() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestShouldJSONContainWithKey(t *testing.T) { + type args struct { + actual interface{} + expected []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // Objects and arrays + { + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{"c", `{"x":1,"y":2}`}, + }, + }, + { + // Spaces, newlines, tabs and key order (including in nested objects) don't matter + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{"c", ` { "y" : 2 ,` + "\n\t" + ` "x" : 1 } `}, + }, + }, + { + name: "array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []interface{}{1, 2}}}, + expected: []interface{}{"a", `[1,2]`}, + }, + }, + { + // Spaces, newlines and tabs don't matter + name: "array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []interface{}{1, 2}}}, + expected: []interface{}{"a", ` [ 1 ,` + "\n\t" + ` 2 ] `}, + }, + }, + // Object and array errors + { + name: "bad value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{"a", `2`}, + }, + wantErr: true, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{"a", "1"}, + }, + wantErr: true, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2}}, + expected: []interface{}{"c", `3`}, + }, + wantErr: true, + }, + { + name: "bad array order", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1, 2}}}, + expected: []interface{}{"a", `[2,1]`}, + }, + wantErr: true, + }, + { + name: "object instead of array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`[1]`}, + }, + wantErr: true, + }, + { + name: "array instead of object", + args: args{ + actual: []interface{}{[]interface{}{1}}, + expected: []interface{}{`{"a":1}}`}, + }, + wantErr: true, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1}}}, + expected: []interface{}{`[1]`}, + }, + wantErr: true, + }, + { + name: "missing value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1}}}, + expected: []interface{}{"a"}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ShouldJSONContainWithKey(tt.args.actual, tt.args.expected...); (err != nil) != tt.wantErr { + t.Errorf("ShouldJSONContainWithKey() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestShouldNotJSONContainWithKey(t *testing.T) { + type args struct { + actual interface{} + expected []interface{} + } + tests := []struct { + name string + args args + wantErr bool + }{ + // Objects and arrays + { + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{"c", `{"x":1,"y":2}`}, + }, + wantErr: true, + }, + { + // Spaces, newlines, tabs and key order (including in nested objects) don't matter + name: "object", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2, "c": map[string]interface{}{"x": 1, "y": 2}}}, + expected: []interface{}{"c", ` { "y" : 2 ,` + "\n\t" + ` "x" : 1 } `}, + }, + wantErr: true, + }, + { + name: "array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []interface{}{1, 2}}}, + expected: []interface{}{"a", `[1,2]`}, + }, + wantErr: true, + }, + { + // Spaces, newlines and tabs don't matter + name: "array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []interface{}{1, 2}}}, + expected: []interface{}{"a", ` [ 1 ,` + "\n\t" + ` 2 ] `}, + }, + wantErr: true, + }, + // Object and array errors + { + name: "bad value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{"a", `2`}, + }, + }, + { + name: "bad type", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{"a", "1"}, + }, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1, "b": 2}}, + expected: []interface{}{"c", `3`}, + }, + }, + { + name: "bad array order", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1, 2}}}, + expected: []interface{}{"a", `[2,1]`}, + }, + }, + { + name: "object instead of array", + args: args{ + actual: []interface{}{map[string]interface{}{"a": 1}}, + expected: []interface{}{`[1]`}, + }, + wantErr: true, + }, + { + name: "array instead of object", + args: args{ + actual: []interface{}{[]interface{}{1}}, + expected: []interface{}{`{"a":1}}`}, + }, + wantErr: true, + }, + { + name: "missing key", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1}}}, + expected: []interface{}{`[1]`}, + }, + wantErr: true, + }, + { + name: "missing value", + args: args{ + actual: []interface{}{map[string]interface{}{"a": []float64{1}}}, + expected: []interface{}{"a"}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ShouldNotJSONContainWithKey(tt.args.actual, tt.args.expected...); (err != nil) != tt.wantErr { + t.Errorf("ShouldNotJSONContainWithKey() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + func TestShouldContainKey(t *testing.T) { type args struct { actual interface{} diff --git a/tests/assertions/ShouldJSONContain.yml b/tests/assertions/ShouldJSONContain.yml new file mode 100644 index 00000000..ec5df077 --- /dev/null +++ b/tests/assertions/ShouldJSONContain.yml @@ -0,0 +1,21 @@ +name: Assertions testsuite +testcases: +- name: test assertion ShouldJSONContain + steps: + - script: | + echo '[ + { + "a" : 1, + "b" : 2, + "c" : { + "x":1, + "y":2 + } + }, + { + "bar": "baz" + } + ]' + assertions: + - result.systemoutjson ShouldJSONContain ' { "c":{ "y" :2 , "x" :1 }, "b" :2 , "a" :1 } ' + - result.systemoutjson ShouldJSONContain ' { "bar":"baz" } ' \ No newline at end of file diff --git a/tests/assertions/ShouldJSONContainWithKey.yml b/tests/assertions/ShouldJSONContainWithKey.yml new file mode 100644 index 00000000..8bab5931 --- /dev/null +++ b/tests/assertions/ShouldJSONContainWithKey.yml @@ -0,0 +1,31 @@ +name: Assertions testsuite +testcases: +- name: test assertion ShouldJSONContainWithKey + steps: + - script: echo '[{"foo":"bar"}, {"baz":"baz"}]' + assertions: + - result.systemoutjson ShouldJSONContainWithKey foo bar + - script: | + echo '[ + { + "o" : { + "a" : 1, + "b" : 2, + "c" : { + "x":1, + "y":2 + } + }, + "a" : [1,2], + "s" : "foo", + "n" : 1.2, + "t" : true, + "f" : false, + "z" : null + }, + { + "bar": "baz" + } + ]' + assertions: + - result.systemoutjson ShouldJSONContainWithKey o ' { "c":{ "y" :2 , "x" :1 }, "b" :2 , "a" :1 } ' \ No newline at end of file diff --git a/tests/assertions/ShouldNotJSONContain.yml b/tests/assertions/ShouldNotJSONContain.yml new file mode 100644 index 00000000..51ed4f43 --- /dev/null +++ b/tests/assertions/ShouldNotJSONContain.yml @@ -0,0 +1,20 @@ +name: Assertions testsuite +testcases: +- name: test assertion ShouldNotJSONContain + steps: + - script: | + echo '[ + { + "a" : 1, + "b" : 2, + "c" : { + "x":1, + "y":2 + } + }, + { + "bar": "baz" + } + ]' + assertions: + - result.systemoutjson ShouldNotJSONContain ' { "bar":"baz" } ' \ No newline at end of file diff --git a/tests/assertions/ShouldNotJSONContainWithKey.yml b/tests/assertions/ShouldNotJSONContainWithKey.yml new file mode 100644 index 00000000..d7a7e187 --- /dev/null +++ b/tests/assertions/ShouldNotJSONContainWithKey.yml @@ -0,0 +1,28 @@ +name: Assertions testsuite +testcases: +- name: test assertion ShouldNotJSONContainWithKey + steps: + - script: | + echo '[ + { + "o" : { + "a" : 1, + "b" : 2, + "c" : { + "x":1, + "y":2 + } + }, + "a" : [1,2], + "s" : "foo", + "n" : 1.2, + "t" : true, + "f" : false, + "z" : null + }, + { + "bar": "baz" + } + ]' + assertions: + - result.systemoutjson ShouldNotJSONContainWithKey o ' { "c":{ "y" :20 , "x" :10 }, "b" :20 , "a" :10 } ' \ No newline at end of file