-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauth_test.go
82 lines (64 loc) · 1.94 KB
/
auth_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
package cloudns
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestAuth_GetParams_None(t *testing.T) {
// given
auth := NewAuth()
// when
params := auth.GetParams()
// then
assert.Len(t, params, 0, "should return zero parameters")
}
func TestAuth_GetParams_AuthUserID(t *testing.T) {
// given
const userID int = 13
const password string = "test"
auth := AuthUserID(userID, password)
client, err := New(auth)
assert.NoError(t, err)
// when
params := client.auth.GetParams()
// then
assert.Len(t, params, 2, "should return two parameters")
assert.Equal(t, userID, params["auth-id"], "parameter `auth-id` should match")
assert.Equal(t, password, params["auth-password"], "parameter `auth-password` should match")
}
func TestAuth_GetParams_SubUserID(t *testing.T) {
// given
const subUserID int = 42
const password string = "dummy"
auth := AuthSubUserID(subUserID, password)
client, err := New(auth)
assert.NoError(t, err)
// when
params := client.auth.GetParams()
// then
assert.Len(t, params, 2, "should return two parameters")
assert.Equal(t, subUserID, params["sub-auth-id"], "parameter `auth-id` should match")
assert.Equal(t, password, params["auth-password"], "parameter `auth-password` should match")
}
func TestAuth_GetParams_SubUserName(t *testing.T) {
// given
const subUserName string = "hello"
const password string = "world"
auth := AuthSubUserName("hello", "world")
client, err := New(auth)
assert.NoError(t, err)
// when
params := client.auth.GetParams()
// then
assert.Len(t, params, 2, "should return two parameters")
assert.Equal(t, subUserName, params["sub-auth-user"], "parameter `auth-id` should match")
assert.Equal(t, password, params["auth-password"], "parameter `auth-password` should match")
}
func TestAuth_GetParams_Invalid(t *testing.T) {
// given
auth := NewAuth()
auth.Type = -1
// then
assert.Panics(t, func() {
auth.GetParams()
}, "should panic with invalid auth type")
}