-
Notifications
You must be signed in to change notification settings - Fork 12
/
revai_test.go
80 lines (63 loc) · 1.51 KB
/
revai_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package revai
import (
"net/http"
"net/url"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
const (
testUserAgent = "test-user-agent"
testBaseURL = "http://test.com"
)
func TestNewClient(t *testing.T) {
c := NewClient("API-KEY")
assert.NotNil(t, c)
}
func TestNewClientWithOptions(t *testing.T) {
testHttpClient := &http.Client{
Timeout: 1 * time.Second,
}
u, err := url.Parse(testBaseURL)
if err != nil {
t.Error(err)
}
c := NewClient(
"API-KEY",
HTTPClient(testHttpClient),
UserAgent("test-user-agent"),
BaseURL(u),
)
assert.NotNil(t, c)
assert.Equal(t, c.UserAgent, testUserAgent, "user agent should match passed in user agent")
assert.Equal(t, c.BaseURL, u, "base url should match passed in base url")
assert.Equal(t, c.HTTPClient, testHttpClient, "http client should match passed in http client")
}
func TestUserAgent(t *testing.T) {
c := NewClient(
"api-key",
UserAgent(testUserAgent),
)
assert.Equal(t, c.UserAgent, testUserAgent, "user agent should match passed in user agent")
}
func TestBaseURL(t *testing.T) {
u, err := url.Parse(testBaseURL)
if err != nil {
t.Error(err)
}
c := NewClient(
"api-key",
BaseURL(u),
)
assert.Equal(t, c.BaseURL, u, "base url should match passed in base url")
}
func TestHttpClient(t *testing.T) {
testHttpClient := &http.Client{
Timeout: 1 * time.Minute,
}
c := NewClient(
"api-key",
HTTPClient(testHttpClient),
)
assert.Equal(t, c.HTTPClient, testHttpClient, "http client should match passed in http client")
}