Skip to content

Commit

Permalink
remove esMock struct
Browse files Browse the repository at this point in the history
Due to previous refactoring this is not needed anymore
  • Loading branch information
endorama committed Oct 28, 2024
1 parent d2ee0f2 commit dd93772
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions internal/elasticsearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,18 @@ func TestClientCustomUserAgent(t *testing.T) {
}
}

type esMock struct {
responder http.HandlerFunc
ClusterUUID string
UUID string
}

func (h *esMock) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Elastic-Product", "Elasticsearch")

switch {
case r.Method == http.MethodPost && r.URL.Path == "/_bulk":
h.responder(w, r)
return
default:
http.Error(w, "unsupported request", 419) // Signal unexpected error
return
func esMockHandler(responder http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Elastic-Product", "Elasticsearch")

switch {
case r.Method == http.MethodPost && r.URL.Path == "/_bulk":
responder(w, r)
return
default:
http.Error(w, "unsupported request", 419) // Signal unexpected error
return
}
}
}

Expand Down Expand Up @@ -155,7 +151,7 @@ func TestClientRetryableStatuses(t *testing.T) {
w.WriteHeader(http.StatusOK)
})

es := esMock{responder: handler, ClusterUUID: "8f8d1c95-dde0-4c11-bf27-063e2a819a4c", UUID: "b97b91b3-16e0-49e2-a635-000c97059b46"}
es := esMockHandler(handler)
srv := httptest.NewServer(&es)
defer srv.Close()

Expand Down

0 comments on commit dd93772

Please sign in to comment.