mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 16:59:34 +08:00
feat: support html extraction with regex #87
This commit is contained in:
35
response_test.go
Normal file
35
response_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package hrp
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
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 {
|
||||
raw string
|
||||
expected string
|
||||
}{
|
||||
{"covering (.*) testing,", "API"},
|
||||
{" (.*) to", "aims"},
|
||||
{"^(.*) aims", "hrp"},
|
||||
{".* (.*?)$", "(DEM)."},
|
||||
}
|
||||
// new response object
|
||||
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.searchRegexp(data.raw)) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user