in ops/ops.go [148:180]
func (o Operative) Query(query string) Operative {
if err := isErrorOrNotExist(o); err != nil {
o.Exist = false
o.err = err
return o
}
o.Reference = fmt.Sprintf("%s?%s", o.Reference, query)
var bytes []byte
// If the actual value is a string, we assume it is JSON and try to parse it.
// Otherwise, we marshal it to JSON and try to parse it.
actual, ok := o.Actual.(string)
if ok {
bytes = []byte(actual)
} else {
bytes, _ = json.Marshal(o.Actual)
}
if !gjson.ValidBytes(bytes) {
o.err = testerror.Newf(
"%s: actual value %s not valid JSON",
o.Reference,
o.Actual,
)
o.Actual = nil
return o
}
o.Actual = gjson.GetBytes(bytes, query).Value()
if o.Actual == nil {
o.Exist = false
}
return o
}