Skip to content

Commit

Permalink
Fix: JSON path value assertion needs expression and value
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
  • Loading branch information
mem committed May 17, 2023
1 parent 21b9498 commit 4c25c8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions pkg/pb/synthetic_monitoring/checks_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,13 @@ func (a *MultiHttpEntryAssertion) Validate() error {
return ErrInvalidMultiHttpAssertion
}

// Expression is not allowed.
if len(a.Expression) != 0 {
// Expression is required
if len(a.Expression) == 0 {
return ErrInvalidMultiHttpAssertion
}

// Condition is covered above

case MultiHttpEntryAssertionType_JSON_PATH_ASSERTION:
// Subject must not be set
if a.Subject != 0 {
Expand Down
16 changes: 9 additions & 7 deletions pkg/pb/synthetic_monitoring/checks_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,18 +1283,20 @@ func TestMultiHttpEntryAssertionValidate(t *testing.T) {
},
"json path value with valid value": {
input: &MultiHttpEntryAssertion{
Type: MultiHttpEntryAssertionType_JSON_PATH_VALUE,
Condition: MultiHttpEntryAssertionConditionVariant_CONTAINS,
Value: "bar",
Type: MultiHttpEntryAssertionType_JSON_PATH_VALUE,
Condition: MultiHttpEntryAssertionConditionVariant_CONTAINS,
Expression: "$.data",
Value: "foo",
},
expectError: false,
},
"json path value does not allow for setting the subject": {
input: &MultiHttpEntryAssertion{
Type: MultiHttpEntryAssertionType_JSON_PATH_VALUE,
Subject: MultiHttpEntryAssertionSubjectVariant_RESPONSE_HEADERS, // invalid
Condition: MultiHttpEntryAssertionConditionVariant_CONTAINS,
Value: "bar",
Type: MultiHttpEntryAssertionType_JSON_PATH_VALUE,
Subject: MultiHttpEntryAssertionSubjectVariant_RESPONSE_HEADERS, // invalid
Condition: MultiHttpEntryAssertionConditionVariant_CONTAINS,
Expression: "$.data",
Value: "foo",
},
expectError: true,
},
Expand Down

0 comments on commit 4c25c8e

Please sign in to comment.