@@ -19,13 +19,15 @@ import (
1919// ServerSetup type contains the Method, Path, Body and Response strings, as well as the HTTP Status code.
2020type ServerSetup struct {
2121Method ,Path ,Body ,Response string
22+ QueryParams url.Values
2223HTTPStatus int
2324extraChecksFn func (t * testing.T ,r * http.Request )
2425}
2526
2627func buildTestServer (t * testing.T ,setups []* ServerSetup ,tls bool )* httptest.Server {
2728handlerFunc := http .HandlerFunc (func (w http.ResponseWriter ,r * http.Request ) {
2829requestBytes ,_ := ioutil .ReadAll (r .Body )
30+ requestQueryParameters := r .URL .Query ()
2931requestBody := string (requestBytes )
3032
3133matched := false
@@ -38,6 +40,14 @@ func buildTestServer(t *testing.T, setups []*ServerSetup, tls bool) *httptest.Se
3840t .Fatalf ("request body not matching: %s != %s" ,requestBody ,setup .Body )
3941}
4042
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+
4151if r .Method == setup .Method && r .URL .EscapedPath ()== setup .Path && requestBody == setup .Body {
4252matched = true
4353if setup .HTTPStatus == 0 {
@@ -549,6 +559,27 @@ func TestDeleteIndex(t *testing.T) {
549559}
550560}
551561
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+
552583func TestOpenIndex (t * testing.T ) {
553584testSetup := & ServerSetup {
554585Method :"POST" ,