/
client_test.go
106 lines (91 loc) · 3.35 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2017 Avaya Cloud Inc. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package zang
import (
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func newTestClient() (*Client, error) {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
ApiVersion: ZangApiVersion,
AccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
AuthToken: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
ResponseContentType: "json",
})
if err != nil {
return nil, err
}
return &Client{Config: config}, nil
}
func TestNewClient(t *testing.T) {
//Convey("New Client With Defaults (No AccountSid)", t, func() {
// client, err := NewClient()
// So(client, ShouldBeNil)
// So(err.Error(), ShouldContainSubstring, "Make sure to provide valid AccountSid")
//})
Convey("New custom client config expects valid api url", t, func() {
config, err := NewCustomConfig(&Config{})
So(config, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Make sure to provide valid Api URL.")
})
Convey("New custom client config expects valid api version", t, func() {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
})
So(config, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Make sure to provide valid api version.")
})
Convey("New custom client config expects valid auth token", t, func() {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
ApiVersion: ZangApiVersion,
AccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
})
So(config, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Make sure to provide valid AuthToken.")
})
Convey("New custom client config expects response content type", t, func() {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
ApiVersion: ZangApiVersion,
AccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
AuthToken: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
})
So(config, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Make sure to provide valid response content type.")
})
Convey("New custom client config expects response valid content type", t, func() {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
ApiVersion: ZangApiVersion,
AccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
AuthToken: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
ResponseContentType: "csv",
})
So(config, ShouldBeNil)
So(err.Error(), ShouldContainSubstring, "Make sure to provide valid response content type.")
})
Convey("New custom client config should pass", t, func() {
config, err := NewCustomConfig(&Config{
ApiUrl: ZangApiUrl,
ApiVersion: ZangApiVersion,
AccountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
AuthToken: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
ResponseContentType: "json",
})
So(config, ShouldNotBeNil)
So(err, ShouldBeNil)
})
Convey("New Client with proper access credentials validates fine", t, func() {
os.Setenv("ZANG_CLOUD_ACCOUNT_SID", "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
os.Setenv("ZANG_CLOUD_AUTH_TOKEN", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
defer os.Setenv("ZANG_CLOUD_ACCOUNT_SID", "")
defer os.Setenv("ZANG_CLOUD_AUTH_TOKEN", "")
client, err := NewClient()
So(client, ShouldNotBeNil)
So(err, ShouldBeNil)
})
}