-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_test.go
163 lines (158 loc) · 2.88 KB
/
account_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"reflect"
"testing"
)
func TestNewAccountClient_ok(t *testing.T) {
client, err := NewAccountClient("http", "localhost", 9000, 1)
if err != nil {
t.Errorf("got %s want nil", err.Error())
}
expected := "http://localhost:9000/v1"
if client.baseUrl.String() != expected {
t.Errorf("String() = %v, want %v", client.baseUrl.String(), expected)
}
}
func TestNewAccountClient(t *testing.T) {
type args struct {
protocol string
host string
port int
version int
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "ok",
args: args{
protocol: "https",
host: "localhost",
port: 9000,
version: 1,
},
want: "https://localhost:9000/v1",
wantErr: false,
},
{
name: "invalid protocol",
args: args{
protocol: "aaaa",
host: "localhost",
port: 9000,
},
want: "",
wantErr: true,
},
{
name: "invalid port",
args: args{
protocol: "http",
host: "localhost",
port: 0,
},
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewAccountClient(tt.args.protocol, tt.args.host, tt.args.port, tt.args.version)
if (err != nil) != tt.wantErr {
t.Errorf("NewAccountClient() error = %v, wantErr %v", err, tt.wantErr)
return
}
actual := got.baseUrl
var actualStr string
if actual == nil {
actualStr = ""
} else {
actualStr = actual.String()
}
if !reflect.DeepEqual(actualStr, tt.want) {
t.Errorf("NewAccountClient() got = %v, want %v", actualStr, tt.want)
}
})
}
}
func Test_isValidPort(t *testing.T) {
type args struct {
port int
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "ok",
args: args{
port: 8080,
},
wantErr: false,
},
{
name: "low",
args: args{
port: 0,
},
wantErr: true,
},
{
name: "high",
args: args{
port: 999999,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := isValidPort(tt.args.port); (err != nil) != tt.wantErr {
t.Errorf("isValidPort() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_isValidProtocol(t *testing.T) {
type args struct {
protocol string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "ok http",
args: args{
protocol: "http",
},
wantErr: false,
},
{
name: "ok https",
args: args{
protocol: "https",
},
wantErr: false,
},
{
name: "invalid",
args: args{
protocol: "tcp",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := isValidProtocol(tt.args.protocol); (err != nil) != tt.wantErr {
t.Errorf("isValidProtocol() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}