diff --git a/pkg/handlers/handlers.go b/pkg/handlers/handlers.go deleted file mode 100644 index e944daf1..00000000 --- a/pkg/handlers/handlers.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Copyright 2020 VMware, Inc. -SPDX-License-Identifier: Apache-2.0 -*/ - -package handlers - -import "net/http" - -const jsonMimeType = "application/json; charset=utf-8" -const headerNameContentType = "Content-Type" - -func New() http.Handler { - mux := http.NewServeMux() - mux.Handle("/healthz", newHealthzHandler()) - return mux -} diff --git a/pkg/handlers/healthz_handler.go b/pkg/handlers/healthz_handler.go deleted file mode 100644 index d96c3b57..00000000 --- a/pkg/handlers/healthz_handler.go +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright 2020 VMware, Inc. -SPDX-License-Identifier: Apache-2.0 -*/ - -package handlers - -import ( - "encoding/json" - "net/http" -) - -type healthzResponse struct { - Status string `json:"status"` -} - -type healthzHandler struct{} - -func (h healthzHandler) ServeHTTP(responseWriter http.ResponseWriter, _ *http.Request) { - response := healthzResponse{"OK"} - js, _ := json.Marshal(response) - responseWriter.Header().Set(headerNameContentType, jsonMimeType) - _, _ = responseWriter.Write(js) -} - -func newHealthzHandler() http.Handler { - return healthzHandler{} -} diff --git a/pkg/handlers/healthz_handler_test.go b/pkg/handlers/healthz_handler_test.go deleted file mode 100644 index a79950c8..00000000 --- a/pkg/handlers/healthz_handler_test.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2020 VMware, Inc. -SPDX-License-Identifier: Apache-2.0 -*/ - -package handlers_test - -import ( - "context" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/suzerain-io/placeholder-name/pkg/handlers" -) - -func TestHealthzReturnsOkWithJsonBody(t *testing.T) { - expect := require.New(t) - server := httptest.NewServer(handlers.New()) - defer server.Close() - - // Create a request context with a short timeout. - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - - // Initialize an HTTP GET request to /healthz - req, err := http.NewRequestWithContext(ctx, http.MethodGet, server.URL+"/healthz", nil) - expect.NoError(err) - - // Perform the request and assert that we received a response. - response, err := http.DefaultClient.Do(req) - expect.NoError(err) - defer response.Body.Close() - - // Assert that we got an HTTP 200 with the correct content type and JSON body. - expect.Equal(http.StatusOK, response.StatusCode) - expect.Equal("application/json; charset=utf-8", response.Header.Get("content-type")) - body, err := ioutil.ReadAll(response.Body) - expect.NoError(err) - expect.JSONEq(`{"status": "OK"}`, string(body)) -}