Remove unused handlers package

This commit is contained in:
Ryan Richard 2020-07-27 09:27:07 -07:00
parent 63a5381968
commit c9026cd150
3 changed files with 0 additions and 90 deletions

View File

@ -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
}

View File

@ -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{}
}

View File

@ -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))
}