-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_test.go
More file actions
57 lines (51 loc) · 1.42 KB
/
Copy pathoptions_test.go
File metadata and controls
57 lines (51 loc) · 1.42 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
package flashduty
import (
"net/http"
"testing"
"time"
)
func TestNewClientDefaultsAndOptions(t *testing.T) {
if _, err := NewClient(""); err == nil {
t.Fatal("expected error for empty app key")
}
c, err := NewClient("KEY",
WithBaseURL("https://example.test"),
WithTimeout(5*time.Second),
WithUserAgent("ua/1"),
)
if err != nil {
t.Fatal(err)
}
if c.BaseURL.String() != "https://example.test" {
t.Fatalf("BaseURL = %s", c.BaseURL)
}
if c.UserAgent != "ua/1" {
t.Fatalf("UserAgent = %s", c.UserAgent)
}
if c.client.Timeout != 5*time.Second {
t.Fatalf("timeout = %s", c.client.Timeout)
}
}
func TestWithBaseURLInvalidReturnsError(t *testing.T) {
if _, err := NewClient("KEY", WithBaseURL("://bad")); err == nil {
t.Fatal("expected error for invalid base URL")
}
}
func TestWithHTTPClientNilIgnored(t *testing.T) {
c, err := NewClient("KEY", WithHTTPClient(nil))
if err != nil || c.client == nil {
t.Fatalf("nil http client must be ignored, got err=%v client=%v", err, c.client)
}
}
type markerRT struct{ http.RoundTripper }
func TestWithTransportSetsRoundTripper(t *testing.T) {
rt := &markerRT{}
c, err := NewClient("KEY", WithTransport(rt))
if err != nil || c.client.Transport != rt {
t.Fatalf("WithTransport not applied: err=%v transport=%v", err, c.client.Transport)
}
c2, _ := NewClient("KEY", WithTransport(nil))
if c2.client.Transport != nil {
t.Fatalf("nil transport should be ignored")
}
}