-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
contains
to compare json objects (#3687)
* feat: support `contains` to compare json objects * add test for json in span attribute * add suggested tests by Daniel * add doc * add test with deep comparison with arrays * Update docs/docs/concepts/expressions.mdx Co-authored-by: Julianne Fermi <[email protected]> --------- Co-authored-by: Julianne Fermi <[email protected]>
- Loading branch information
1 parent
338439b
commit d2061bc
Showing
7 changed files
with
221 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,6 +373,74 @@ func TestArrayExecution(t *testing.T) { | |
Query: `[31,35,39] contains 42`, | ||
ShouldPass: false, | ||
}, | ||
{ | ||
Name: "should_identify_array_instead_of_json", | ||
Query: `["{}", "{}", "{}"] | type = "array"`, | ||
ShouldPass: true, | ||
}, | ||
} | ||
|
||
executeTestCases(t, testCases) | ||
} | ||
|
||
func TestJSONExecution(t *testing.T) { | ||
testCases := []executorTestCase{ | ||
{ | ||
Name: "should_identify_json_input", | ||
Query: `'{"name": "john", "age": 32, "email": "[email protected]"}' | type = "json"`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_be_able_to_compare_with_subset", | ||
Query: `'{"name": "john", "age": 32, "email": "[email protected]"}' contains '{"email": "[email protected]", "name": "john"}'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_be_able_to_compare_with_subset_ignoring_order", | ||
Query: `'{"name": "john", "age": 32, "email": "[email protected]"}' contains '{"email": "[email protected]", "name": "john", "age": 32}'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_be_able_to_compare_deep_objects_in_subset", | ||
Query: `'{"name": "john", "age": 32, "email": "[email protected]", "company": {"name": "Company", "address": "1234 Agora Street"}}' contains '{"email": "[email protected]", "name": "john", "company": {"name": "Company"}}'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_be_able_to_compare_array_of_json_objects", | ||
Query: `'[{"name": "john", "age": 32}, {"name": "Maria", "age": 63}]' contains '[{"age": 63}, {"age": 32}]'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_match_complete_arrays", | ||
Query: `'{"numbers": [0,1,2,3,4]}' contains '{"numbers": [0,1,2,3,4]}'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_fail_when_array_doesnt_match_size_and_order", | ||
Query: `'{"numbers": [0,1,2,3,4]}' contains '{"numbers": [0,1]}'`, | ||
ShouldPass: false, | ||
}, | ||
{ | ||
Name: "should_fail_when_array_contains_same_elements_but_different_types", | ||
Query: `'{"numbers": [0,1,2,3,4]}' contains '{"numbers": [0,1,"2","3",4]}'`, | ||
ShouldPass: false, | ||
}, | ||
{ | ||
Name: "should_be_able_to_compare_deep_objects_with_arrays_in_subset", | ||
Query: `'{"name": "john", "age": 32, "email": "[email protected]", "company": {"name": "Company", "address": "1234 Agora Street", "telephones": ["01", "02", "03"]}}' contains '{"email": "[email protected]", "name": "john", "company": {"name": "Company", "telephones": ["01", "02", "03"]}}'`, | ||
ShouldPass: true, | ||
}, | ||
{ | ||
Name: "should_identify_json_input_from_attribute", | ||
Query: `attr:tracetest.response.body contains '{"name": "john"}'`, | ||
ShouldPass: true, | ||
AttributeDataStore: expression.AttributeDataStore{ | ||
Span: traces.Span{ | ||
ID: id.NewRandGenerator().SpanID(), | ||
Attributes: traces.NewAttributes().Set("tracetest.response.body", `{"name": "john", "age": 32, "email": "[email protected]"}`), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCases(t, testCases) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters