feat: parse checkItem before searchField

This commit is contained in:
buyuxiang
2022-04-12 20:07:19 +08:00
parent 7259d12562
commit fcb1fb1575
3 changed files with 44 additions and 8 deletions

View File

@@ -9,6 +9,30 @@ import (
"github.com/stretchr/testify/assert"
)
func TestSearchJmespath(t *testing.T) {
testText := `{"a": {"b": "foo"}, "c": "bar", "d": {"e": [{"f": "foo"}, {"f": "bar"}]}}`
testData := []struct {
raw string
expected string
}{
{"body.a.b", "foo"},
{"body.c", "bar"},
{"body.d.e[0].f", "foo"},
{"body.d.e[1].f", "bar"},
}
resp := http.Response{}
resp.Body = io.NopCloser(strings.NewReader(testText))
respObj, err := newResponseObject(t, newParser(), &resp)
if err != nil {
t.Fail()
}
for _, data := range testData {
if !assert.Equal(t, data.expected, respObj.searchJmespath(data.raw)) {
t.Fail()
}
}
}
func TestSearchRegexp(t *testing.T) {
testText := `hrp aims to be a one-stop solution for HTTP(S) testing, covering API testing, load testing and digital experience monitoring (DEM).`
testData := []struct {