-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_test.go
86 lines (67 loc) · 1.93 KB
/
config_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
81
82
83
84
85
86
package anthropic_test
import (
"net/http"
"testing"
"github.com/liushuangls/go-anthropic/v2"
)
func TestWithBaseURL(t *testing.T) {
fakeBaseURL := "fake-url!"
opt := anthropic.WithBaseURL(fakeBaseURL)
c := anthropic.ClientConfig{}
opt(&c)
if c.BaseURL != fakeBaseURL {
t.Errorf("unexpected BaseURL: %s", c.BaseURL)
}
}
func TestWithAPIVersion(t *testing.T) {
t.Run("single generic version", func(t *testing.T) {
fakeAPIVersion := anthropic.APIVersion("fake-version")
opt := anthropic.WithAPIVersion(fakeAPIVersion)
c := anthropic.ClientConfig{}
opt(&c)
if c.APIVersion != fakeAPIVersion {
t.Errorf("unexpected APIVersion: %s", c.APIVersion)
}
})
}
func TestWithHTTPClient(t *testing.T) {
fakeHTTPClient := http.Client{}
fakeHTTPClient.Timeout = 1234
opt := anthropic.WithHTTPClient(&fakeHTTPClient)
c := anthropic.ClientConfig{}
opt(&c)
if c.HTTPClient != &fakeHTTPClient {
t.Errorf("unexpected HTTPClient: %v", c.HTTPClient)
}
}
func TestWithEmptyMessagesLimit(t *testing.T) {
fakeLimit := uint(1234)
opt := anthropic.WithEmptyMessagesLimit(fakeLimit)
c := anthropic.ClientConfig{}
opt(&c)
if c.EmptyMessagesLimit != fakeLimit {
t.Errorf("unexpected EmptyMessagesLimit: %d", c.EmptyMessagesLimit)
}
}
func TestWithBetaVersion(t *testing.T) {
t.Run("single generic version", func(t *testing.T) {
fakeBetaVersion := anthropic.BetaVersion("fake-version")
opt := anthropic.WithBetaVersion(fakeBetaVersion)
c := anthropic.ClientConfig{}
opt(&c)
if c.BetaVersion[0] != fakeBetaVersion {
t.Errorf("unexpected BetaVersion: %s", c.BetaVersion)
}
if len(c.BetaVersion) != 1 {
t.Errorf("unexpected BetaVersion length: %d", len(c.BetaVersion))
}
})
t.Run("multiple versions", func(t *testing.T) {
opt := anthropic.WithBetaVersion("foo", "bar")
c := anthropic.ClientConfig{}
opt(&c)
if len(c.BetaVersion) != 2 {
t.Errorf("unexpected BetaVersion length: %d", len(c.BetaVersion))
}
})
}