-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathconfig_test.go
162 lines (155 loc) · 3.28 KB
/
config_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
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package clientconfig
import (
"testing"
"github.com/efficientgo/core/testutil"
)
func TestBuildHTTPConfig(t *testing.T) {
for _, tc := range []struct {
desc string
addresses []string
err bool
expected []Config
}{
{
desc: "single addr without path",
addresses: []string{"localhost:9093"},
expected: []Config{
{
HTTPConfig: HTTPConfig{
EndpointsConfig: HTTPEndpointsConfig{
StaticAddresses: []string{"localhost:9093"},
Scheme: "http",
},
},
},
},
},
{
desc: "1st addr without path, 2nd with",
addresses: []string{"localhost:9093", "localhost:9094/prefix"},
expected: []Config{
{
HTTPConfig: HTTPConfig{
EndpointsConfig: HTTPEndpointsConfig{
StaticAddresses: []string{"localhost:9093"},
Scheme: "http",
},
},
},
{
HTTPConfig: HTTPConfig{
EndpointsConfig: HTTPEndpointsConfig{
StaticAddresses: []string{"localhost:9094"},
Scheme: "http",
PathPrefix: "/prefix",
},
},
},
},
},
{
desc: "single addr with path and http scheme",
addresses: []string{"http://localhost:9093"},
expected: []Config{
{
HTTPConfig: HTTPConfig{
EndpointsConfig: HTTPEndpointsConfig{
StaticAddresses: []string{"localhost:9093"},
Scheme: "http",
},
},
},
},
},
{
desc: "single addr with path and https scheme",
addresses: []string{"https://localhost:9093"},
expected: []Config{
{
HTTPConfig: HTTPConfig{
EndpointsConfig: HTTPEndpointsConfig{
StaticAddresses: []string{"localhost:9093"},
Scheme: "https",
},
},
},
},
},
{
desc: "not supported scheme",
addresses: []string{"ttp://localhost:9093"},
err: true,
},
{
desc: "invalid addr",
addresses: []string{"this is not a valid addr"},
err: true,
},
{
desc: "empty addr",
addresses: []string{""},
err: true,
},
} {
t.Run(tc.desc, func(t *testing.T) {
cfg, err := BuildConfigFromHTTPAddresses(tc.addresses)
if tc.err {
testutil.NotOk(t, err)
return
}
testutil.Equals(t, tc.expected, cfg)
})
}
}
func TestBuildGRPCConfig(t *testing.T) {
for _, tc := range []struct {
desc string
addresses []string
err bool
expected []Config
}{
{
desc: "single addr",
addresses: []string{"localhost:9093"},
expected: []Config{
{
GRPCConfig: &GRPCConfig{
EndpointAddrs: []string{"localhost:9093"},
},
},
},
},
{
desc: "multiple addr",
addresses: []string{"localhost:9093", "localhost:9094"},
expected: []Config{
{
GRPCConfig: &GRPCConfig{
EndpointAddrs: []string{"localhost:9093"},
},
},
{
GRPCConfig: &GRPCConfig{
EndpointAddrs: []string{"localhost:9094"},
},
},
},
},
{
desc: "empty addr",
addresses: []string{""},
err: true,
},
} {
t.Run(tc.desc, func(t *testing.T) {
cfg, err := BuildConfigFromGRPCAddresses(tc.addresses)
if tc.err {
testutil.NotOk(t, err)
return
}
testutil.Equals(t, tc.expected, cfg)
})
}
}