Skip to content

Commit

Permalink
Added Array and Boolean assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jul 26, 2024
1 parent e565a0a commit 2a04d1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions requirejson/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ func (obj *JQObject) MustNotBeEmpty(msgAndArgs ...interface{}) {
}
}

// IsTrue test if the JQObject is `true`.
func (obj *JQObject) IsTrue(msgAndArgs ...interface{}) {
obj.MustEqual("true", msgAndArgs...)
}

// IsFalse test if the JQObject is `false`.
func (obj *JQObject) IsFalse(msgAndArgs ...interface{}) {
obj.MustEqual("false", msgAndArgs...)
}

// ArrayMustContain checks if the give JQObject contains the given element.
func (obj *JQObject) ArrayMustContain(jsonElement string, msgAndArgs ...interface{}) {
obj.Query(`any(. == ` + jsonElement + `)`).IsTrue(msgAndArgs...)
}

// Query performs a test on a given json output. A jq-like query is performed
// on the given jsonData and the result is compared with jsonExpected.
// If the output doesn't match the test fails. If msgAndArgs are provided they
Expand Down
2 changes: 2 additions & 0 deletions requirejson/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ func TestJSONAssertions(t *testing.T) {
requirejson.Len(t, in3, 3)

requirejson.Query(t, in, ".list | length", "3")

requirejson.Parse(t, in).Query(".list").ArrayMustContain("20")
}

0 comments on commit 2a04d1a

Please sign in to comment.