-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclient_test.go
84 lines (77 loc) · 1.64 KB
/
client_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
package deepl_test
import (
"fmt"
"testing"
"github.com/michimani/deepl-sdk-go"
"github.com/michimani/deepl-sdk-go/types"
"github.com/stretchr/testify/assert"
)
func TestNewClient(t *testing.T) {
cases := []struct {
name string
authnKey string
planName string
wantErr bool
expect *deepl.Client
}{
{
name: "ok (free)",
authnKey: "test-key",
planName: "free",
wantErr: false,
expect: &deepl.Client{
AuthenticationKey: "test-key",
APIPlanType: types.APIPlanFree,
EndpointBase: fmt.Sprintf("https://%s/%s/", types.DomainFree, types.APIVersion),
},
},
{
name: "ok (pro)",
authnKey: "test-key",
planName: "pro",
wantErr: false,
expect: &deepl.Client{
AuthenticationKey: "test-key",
APIPlanType: types.APIPlanPro,
EndpointBase: fmt.Sprintf("https://%s/%s/", types.DomainPro, types.APIVersion),
},
},
{
name: "DEEPL_API_AUTHN_KEY not set",
authnKey: "",
planName: "free",
wantErr: true,
expect: nil,
},
{
name: "DEEPL_API_PLAN not set",
authnKey: "test-key",
planName: "",
wantErr: true,
expect: nil,
},
{
name: "DEEPL_API_PLAN is invalid",
authnKey: "test-key",
planName: "freeeeeeee",
wantErr: true,
expect: nil,
},
}
for _, c := range cases {
t.Run(c.name, func(tt *testing.T) {
if c.authnKey != "" {
tt.Setenv("DEEPL_API_AUTHN_KEY", c.authnKey)
}
if c.planName != "" {
tt.Setenv("DEEPL_API_PLAN", c.planName)
}
client, err := deepl.NewClient()
if c.wantErr {
assert.Error(tt, err)
return
}
assert.Equal(tt, c.expect, client)
})
}
}