@@ -19,13 +19,15 @@ import (
19
19
// ServerSetup type contains the Method, Path, Body and Response strings, as well as the HTTP Status code.
20
20
type ServerSetup struct {
21
21
Method, Path, Body, Response string
22
+
QueryParams url.Values
22
23
HTTPStatus int
23
24
extraChecksFn func(t *testing.T, r *http.Request)
24
25
}
25
26
26
27
func buildTestServer(t *testing.T, setups []*ServerSetup, tls bool) *httptest.Server {
27
28
handlerFunc := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
28
29
requestBytes, _ := ioutil.ReadAll(r.Body)
30
+
requestQueryParameters := r.URL.Query()
29
31
requestBody := string(requestBytes)
30
32
31
33
matched := false
@@ -38,6 +40,14 @@ func buildTestServer(t *testing.T, setups []*ServerSetup, tls bool) *httptest.Se
38
40
t.Fatalf("request body not matching: %s != %s", requestBody, setup.Body)
39
41
}
40
42
43
+
if setup.QueryParams != nil {
44
+
for key, value := range setup.QueryParams {
45
+
if requestQueryParameters.Get(key) != value[0] {
46
+
t.Fatalf("request query parameter not matching: %s != %s", requestQueryParameters.Get(key), value[0])
47
+
}
48
+
}
49
+
}
50
+
41
51
if r.Method == setup.Method && r.URL.EscapedPath() == setup.Path && requestBody == setup.Body {
42
52
matched = true
43
53
if setup.HTTPStatus == 0 {
@@ -549,6 +559,27 @@ func TestDeleteIndex(t *testing.T) {
549
559
}
550
560
}
551
561
562
+
func TestDeleteIndexWithQueryParameters(t *testing.T) {
563
+
testSetup := &ServerSetup{
564
+
Method: "DELETE",
565
+
Path: "/badindex",
566
+
QueryParams: map[string][]string{
567
+
"timeout": {"1m"},
568
+
},
569
+
Response: `{"acknowledged": true}`,
570
+
}
571
+
572
+
host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
573
+
defer ts.Close()
574
+
client := NewClient(host, port)
575
+
576
+
err := client.DeleteIndexWithQueryParameters("badindex", map[string][]string{"timeout": {"1m"}})
577
+
578
+
if err != nil {
579
+
t.Errorf("Unexpected error expected nil, got %s", err)
580
+
}
581
+
}
582
+
552
583
func TestOpenIndex(t *testing.T) {
553
584
testSetup := &ServerSetup{
554
585
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