diff --git a/requirejson/json.go b/requirejson/json.go index 82c2edb..5e4e7a9 100644 --- a/requirejson/json.go +++ b/requirejson/json.go @@ -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 diff --git a/requirejson/json_test.go b/requirejson/json_test.go index 6ef87b1..5e9ef40 100644 --- a/requirejson/json_test.go +++ b/requirejson/json_test.go @@ -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") }