-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_test.go
69 lines (56 loc) · 1.28 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
package moonshot_test
import (
"errors"
"os"
"strconv"
"testing"
"github.com/northes/go-moonshot"
"github.com/stretchr/testify/require"
)
func NewTestClient() (*moonshot.Client, error) {
key, ok := os.LookupEnv("MOONSHOT_KEY")
if !ok {
return nil, errors.New("missing environment variable: MOONSHOT_KEY")
}
debug, ok := os.LookupEnv("MOONSHOT_DEBUG")
if !ok {
debug = "false"
}
cfg := moonshot.NewConfig(
moonshot.WithAPIKey(key),
moonshot.WithHost(moonshot.DefaultHost),
)
isDebug, err := strconv.ParseBool(debug)
if err != nil {
return nil, err
}
if isDebug {
cfg.Debug = isDebug
}
return moonshot.NewClientWithConfig(cfg)
}
func TestNewClient(t *testing.T) {
tt := require.New(t)
cli, err := moonshot.NewClient("")
tt.NotNil(err)
tt.Nil(cli)
cli, err = moonshot.NewClient("xxxx")
tt.Nil(err)
tt.NotNil(cli)
}
func TestNewClientWithConfig(t *testing.T) {
tt := require.New(t)
cli, err := moonshot.NewClientWithConfig(nil)
tt.NotNil(err, "must got a required api key error")
tt.Nil(cli)
cli, err = moonshot.NewClientWithConfig(moonshot.NewConfig())
tt.NotNil(err, "must got a required api key error")
tt.Nil(cli)
cli, err = moonshot.NewClientWithConfig(
moonshot.NewConfig(
moonshot.WithAPIKey("xxxx"),
),
)
tt.Nil(err)
tt.NotNil(cli)
}