forked from danieldanciu/gonduit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialer_test.go
107 lines (87 loc) · 2.34 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
package gonduit
import (
"testing"
"github.com/danieldanciu/gonduit/core"
"github.com/danieldanciu/gonduit/responses"
"github.com/danieldanciu/gonduit/test/server"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
)
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_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",
}),
)
}