-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
66 lines (56 loc) · 1.98 KB
/
Copy patherrors_test.go
File metadata and controls
66 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package scraperapi_test
import (
"errors"
"testing"
scraperapi "github.com/zenrows/zenrows-go-sdk/service/api"
)
func TestNotConfiguredErrorMessage(t *testing.T) {
err := scraperapi.NotConfiguredError{}
if err.Error() != "zenrows fetch client is not configured" {
t.Fatalf("unexpected message: %q", err.Error())
}
}
func TestInvalidHTTPMethodErrorMessage(t *testing.T) {
err := scraperapi.InvalidHTTPMethodError{}
msg := err.Error()
if msg == "" || !contains(msg, "GET") || !contains(msg, "POST") || !contains(msg, "PUT") {
t.Fatalf("expected message to list valid methods, got %q", msg)
}
}
func TestInvalidTargetURLErrorDefaultsMessage(t *testing.T) {
err := scraperapi.InvalidTargetURLError{}
if err.Error() != "invalid target url" {
t.Fatalf("unexpected default message: %q", err.Error())
}
}
func TestInvalidTargetURLErrorWithCustomMsgAndWrappedErr(t *testing.T) {
wrapped := errors.New("boom")
err := scraperapi.InvalidTargetURLError{Msg: "custom", Err: wrapped}
if got := err.Error(); got != "custom: boom" {
t.Fatalf("expected combined message, got %q", got)
}
if !errors.Is(err, wrapped) {
t.Fatal("expected errors.Is to unwrap to the underlying error")
}
}
func TestInvalidTargetURLErrorWithoutWrappedErr(t *testing.T) {
err := scraperapi.InvalidTargetURLError{Msg: "custom"}
if got := err.Error(); got != "custom" {
t.Fatalf("expected message without a wrapped error suffix, got %q", got)
}
if err.Unwrap() != nil {
t.Fatal("expected Unwrap to return nil when no error was wrapped")
}
}
func TestInvalidParameterErrorDefaultsMessage(t *testing.T) {
err := scraperapi.InvalidParameterError{}
if err.Error() != "invalid parameter" {
t.Fatalf("unexpected default message: %q", err.Error())
}
}
func TestInvalidParameterErrorWithCustomMsg(t *testing.T) {
err := scraperapi.InvalidParameterError{Msg: "screenshot quality must be between 1 and 100"}
if err.Error() != "screenshot quality must be between 1 and 100" {
t.Fatalf("unexpected message: %q", err.Error())
}
}