-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_requests_test.go
105 lines (96 loc) · 2.17 KB
/
client_requests_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
package meili
import "testing"
func TestClientKeyHelpers(t *testing.T) {
var (
masterKey = "link"
privateKey = "private"
pubKey = "public"
)
cases := []struct {
Name string
Options []ClientOption
Get func(c *Client) func() (string, error)
ExpectKey string
ShouldErr bool
}{
{
"basic",
[]ClientOption{WithNoKeys()},
func(c *Client) func() (string, error) { return c.getMasterKey },
"",
false,
},
{
"basic-2",
[]ClientOption{WithNoKeys()},
func(c *Client) func() (string, error) { return c.getAnyKey },
"",
false,
},
{
"basic-master-key",
[]ClientOption{WithMasterKey(masterKey)},
func(c *Client) func() (string, error) { return c.getMasterKey },
masterKey,
false,
},
{
"basic-private-key",
[]ClientOption{WithPrivateKey(privateKey)},
func(c *Client) func() (string, error) { return c.getMasterOrPrivateKey },
privateKey,
false,
},
{
"basic-public-key",
[]ClientOption{WithPublicKey(pubKey)},
func(c *Client) func() (string, error) { return c.getAnyKey },
pubKey,
false,
},
}
for _, c := range cases {
client, err := NewClient("", c.Options...)
if err != nil {
t.Errorf("failed to initialize client, case %q: %s", c.Name, err)
}
key, err := c.Get(client)()
if err != nil {
t.Errorf("failed to get key, case %q: %s", c.Name, err)
}
if key != c.ExpectKey {
t.Errorf("did not get the right key for case %q: got %q want %q", c.Name, key, c.ExpectKey)
}
}
}
func TestClientRouteHelper(t *testing.T) {
cases := []struct {
Name string
Address string
Route string
Expect string
}{
{
"basic",
"http://127.0.0.1:7700",
"/indexes",
"http://127.0.0.1:7700/indexes",
},
{
"basic-2",
"http://127.0.0.1:7700/",
"/indexes",
"http://127.0.0.1:7700/indexes",
},
}
for _, c := range cases {
client, err := NewClient(c.Address, WithNoKeys())
if err != nil {
t.Errorf("could not instantiate client for case %q: %s", c.Name, err)
}
routeResult := client.getRoute(c.Route)
if routeResult != c.Expect {
t.Errorf("did not get expected route for case %q: got %q want %q", c.Name, routeResult, c.Expect)
}
}
}