forked from etcinit/gonduit
-
Notifications
You must be signed in to change notification settings - Fork 11
/
dialer_test.go
122 lines (98 loc) · 2.59 KB
/
dialer_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
package gonduit
import (
"testing"
"time"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/thought-machine/gonduit/core"
"github.com/thought-machine/gonduit/responses"
"github.com/thought-machine/gonduit/test/server"
)
func TestDial(t *testing.T) {
s := server.New()
defer s.Close()
s.RegisterCapabilities()
_, err := Dial(s.GetURL(), &core.ClientOptions{
APIToken: "some-token",
})
assert.Nil(t, err)
}
func TestDial_withTimeout(t *testing.T) {
s := server.New()
defer s.Close()
s.RegisterCapabilities()
_, err := Dial(s.GetURL(), &core.ClientOptions{
APIToken: "some-token",
Timeout: 60 * time.Second,
})
assert.Nil(t, err)
}
func TestDial_withInvalid(t *testing.T) {
s := server.New()
defer s.Close()
s.RegisterMethod("conduit.getcapabilities", 200, gin.H{
"fake": "fake",
})
_, err := Dial(s.GetURL(), &core.ClientOptions{
APIToken: "some-token",
})
assert.NotNil(t, err)
}
func TestAssertSupportedCapabilities(t *testing.T) {
response := responses.ConduitCapabilitiesResponse{
Input: []string{"urlencoded"},
Output: []string{"json"},
}
assert.Nil(t, assertSupportedCapabilities(response, &core.ClientOptions{}))
}
func TestAssertSupportedCapabilities_withMissingInput(t *testing.T) {
response := responses.ConduitCapabilitiesResponse{
Input: []string{"fake"},
Output: []string{"json"},
}
assert.Equal(
t,
core.ErrURLEncodedInputUnsupported,
assertSupportedCapabilities(response, &core.ClientOptions{}),
)
}
func TestAssertSupportedCapabilities_withMissingOutput(t *testing.T) {
response := responses.ConduitCapabilitiesResponse{
Input: []string{"urlencoded"},
Output: []string{"fake"},
}
assert.Equal(
t,
core.ErrJSONOutputUnsupported,
assertSupportedCapabilities(response, &core.ClientOptions{}),
)
}
func TestAssertSupportedCapabilities_withNoToken(t *testing.T) {
response := responses.ConduitCapabilitiesResponse{
Authentication: []string{"session"},
Input: []string{"urlencoded"},
Output: []string{"json"},
}
assert.Equal(
t,
core.ErrTokenAuthUnsupported,
assertSupportedCapabilities(response, &core.ClientOptions{
APIToken: "super-secret-token",
}),
)
}
func TestAssertSupportedCapabilities_withNoCertificate(t *testing.T) {
response := responses.ConduitCapabilitiesResponse{
Authentication: []string{"token"},
Input: []string{"urlencoded"},
Output: []string{"json"},
}
assert.Equal(
t,
core.ErrSessionAuthUnsupported,
assertSupportedCapabilities(response, &core.ClientOptions{
Cert: "super-secret-token",
CertUser: "alice",
}),
)
}