summaryrefslogtreecommitdiff
path: root/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go')
-rw-r--r--vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go75
1 files changed, 0 insertions, 75 deletions
diff --git a/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go b/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go
deleted file mode 100644
index 187618e..0000000
--- a/vendor/github.com/playwright-community/playwright-go/apiresponse_assertions.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package playwright
-
-import (
- "errors"
- "fmt"
- "regexp"
- "strings"
-)
-
-type apiResponseAssertionsImpl struct {
- actual APIResponse
- isNot bool
-}
-
-func newAPIResponseAssertions(actual APIResponse, isNot bool) *apiResponseAssertionsImpl {
- return &apiResponseAssertionsImpl{
- actual: actual,
- isNot: isNot,
- }
-}
-
-func (ar *apiResponseAssertionsImpl) Not() APIResponseAssertions {
- return newAPIResponseAssertions(ar.actual, true)
-}
-
-func (ar *apiResponseAssertionsImpl) ToBeOK() error {
- if ar.isNot != ar.actual.Ok() {
- return nil
- }
- message := fmt.Sprintf(`Response status expected to be within [200..299] range, was %v`, ar.actual.Status())
- if ar.isNot {
- message = strings.ReplaceAll(message, "expected to", "expected not to")
- }
- logList, err := ar.actual.(*apiResponseImpl).fetchLog()
- if err != nil {
- return err
- }
- log := strings.Join(logList, "\n")
- if log != "" {
- message += "\nCall log:\n" + log
- }
-
- isTextEncoding := false
- contentType, ok := ar.actual.Headers()["content-type"]
- if ok {
- isTextEncoding = isTexualMimeType(contentType)
- }
- if isTextEncoding {
- text, err := ar.actual.Text()
- if err == nil {
- message += fmt.Sprintf(`\n Response Text:\n %s`, subString(text, 0, 1000))
- }
- }
- return errors.New(message)
-}
-
-func isTexualMimeType(mimeType string) bool {
- re := regexp.MustCompile(`^(text\/.*?|application\/(json|(x-)?javascript|xml.*?|ecmascript|graphql|x-www-form-urlencoded)|image\/svg(\+xml)?|application\/.*?(\+json|\+xml))(;\s*charset=.*)?$`)
- return re.MatchString(mimeType)
-}
-
-func subString(s string, start, length int) string {
- if start < 0 {
- start = 0
- }
- if length < 0 {
- length = 0
- }
- rs := []rune(s)
- end := start + length
- if end > len(rs) {
- end = len(rs)
- }
- return string(rs[start:end])
-}