-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathoption_test.go
61 lines (43 loc) · 1.26 KB
/
option_test.go
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
package httpclient_test
import (
"fmt"
"net/http"
"net/http/cookiejar"
"testing"
"time"
"github.com/ankorstore/yokai/httpclient"
"github.com/stretchr/testify/assert"
)
func TestWithTransport(t *testing.T) {
t.Parallel()
opts := httpclient.DefaultHttpClientOptions()
transport := &http.Transport{}
httpclient.WithTransport(transport)(&opts)
assert.Equal(t, transport, opts.Transport)
}
func TestWithCheckRedirect(t *testing.T) {
t.Parallel()
opts := httpclient.DefaultHttpClientOptions()
req, _ := http.NewRequest(http.MethodGet, "https://test.com", nil)
checkRedirectFunc := func(req *http.Request, via []*http.Request) error {
return fmt.Errorf("custom error")
}
httpclient.WithCheckRedirect(checkRedirectFunc)(&opts)
err := opts.CheckRedirect(req, []*http.Request{})
assert.Error(t, err)
assert.Equal(t, "custom error", err.Error())
}
func TestWithCookieJar(t *testing.T) {
t.Parallel()
opts := httpclient.DefaultHttpClientOptions()
jar, _ := cookiejar.New(nil)
httpclient.WithCookieJar(jar)(&opts)
assert.Equal(t, jar, opts.Jar)
}
func TestWithTimeout(t *testing.T) {
t.Parallel()
opts := httpclient.DefaultHttpClientOptions()
timeout := time.Second * 20
httpclient.WithTimeout(timeout)(&opts)
assert.Equal(t, timeout, opts.Timeout)
}