@@ -2211,6 +2211,105 @@ func TestClusterAllocationExplain(t *testing.T) {
2211
2211
}
2212
2212
}
2213
2213
2214
+
func TestClusterAllocationExplainWithQueryParams(t *testing.T) {
2215
+
shardID := 0
2216
+
tests := []struct {
2217
+
name string
2218
+
request *ClusterAllocationExplainRequest
2219
+
params map[string]string
2220
+
expectedBody string
2221
+
}{
2222
+
{
2223
+
name: "with nil request",
2224
+
request: nil,
2225
+
expectedBody: "",
2226
+
params: map[string]string{},
2227
+
},
2228
+
{
2229
+
name: "with current_node set",
2230
+
request: &ClusterAllocationExplainRequest{
2231
+
CurrentNode: "test-node",
2232
+
},
2233
+
expectedBody: `{"current_node":"test-node"}`,
2234
+
params: map[string]string{},
2235
+
},
2236
+
{
2237
+
name: "with index set",
2238
+
request: &ClusterAllocationExplainRequest{
2239
+
Index: "test-index",
2240
+
},
2241
+
expectedBody: `{"index":"test-index"}`,
2242
+
params: map[string]string{},
2243
+
},
2244
+
{
2245
+
name: "with primary set",
2246
+
request: &ClusterAllocationExplainRequest{
2247
+
Primary: true,
2248
+
},
2249
+
expectedBody: `{"primary":true}`,
2250
+
params: map[string]string{},
2251
+
},
2252
+
{
2253
+
name: "with shard set",
2254
+
request: &ClusterAllocationExplainRequest{
2255
+
Shard: &shardID,
2256
+
},
2257
+
expectedBody: `{"shard":0}`,
2258
+
params: map[string]string{},
2259
+
},
2260
+
{
2261
+
name: "with pretty param",
2262
+
request: nil,
2263
+
params: map[string]string{
2264
+
"pretty": "true",
2265
+
},
2266
+
},
2267
+
{
2268
+
name: "with multiple params",
2269
+
request: nil,
2270
+
params: map[string]string{
2271
+
"pretty": "true",
2272
+
"include_disk_info": "true",
2273
+
"include_yes_decisions": "true",
2274
+
},
2275
+
},
2276
+
}
2277
+
2278
+
for _, tt := range tests {
2279
+
tc := tt
2280
+
t.Run(tc.name, func(t *testing.T) {
2281
+
testSetup := &ServerSetup{
2282
+
Method: "GET",
2283
+
Path: "/_cluster/allocation/explain",
2284
+
Body: tc.expectedBody,
2285
+
}
2286
+
2287
+
if len(tc.params) > 0 {
2288
+
testSetup.extraChecksFn = func(t *testing.T, r *http.Request) {
2289
+
vals := r.URL.Query()
2290
+
if len(vals) != len(tc.params) {
2291
+
t.Errorf("expected %d query params but got %d", len(tc.params), len(vals))
2292
+
}
2293
+
for param, val := range tc.params {
2294
+
if actual := vals.Get(param); actual != val {
2295
+
t.Errorf("expected val '%s' for query parameter '%s' but got '%s'", val, param, actual)
2296
+
}
2297
+
}
2298
+
}
2299
+
}
2300
+
2301
+
host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
2302
+
defer ts.Close()
2303
+
client := NewClient(host, port)
2304
+
2305
+
_, err := client.ClusterAllocationExplainWithQueryParams(tc.request, tc.params)
2306
+
if err != nil {
2307
+
t.Fatalf("Unexpected error. expected nil, got %s", err)
2308
+
}
2309
+
})
2310
+
}
2311
+
}
2312
+
2214
2313
func TestReroute(t *testing.T) {
2215
2314
testSetup := &ServerSetup{
2216
2315
Method: "POST",
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4