From 0f521020c8147139ed8995ea2f2154b32f76bac0 Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Mon, 10 Apr 2017 15:55:47 +0200 Subject: [PATCH] Remove unneeded index handler --- index-view.go | 10 ---------- index-view_test.go | 36 ------------------------------------ main.go | 2 +- 3 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 index-view.go delete mode 100644 index-view_test.go diff --git a/index-view.go b/index-view.go deleted file mode 100644 index 45a60e7..0000000 --- a/index-view.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import "net/http" - -// IndexViewHandler forwards to "/buckets" -func IndexViewHandler() http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/buckets", http.StatusPermanentRedirect) - }) -} diff --git a/index-view_test.go b/index-view_test.go deleted file mode 100644 index f3f59a6..0000000 --- a/index-view_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestIndexViewHandler(t *testing.T) { - assert := assert.New(t) - - tests := map[string]struct { - expectedStatusCode int - expectedBodyContains string - }{ - "success": { - expectedStatusCode: http.StatusPermanentRedirect, - expectedBodyContains: "Redirect", - }, - } - - for tcID, tc := range tests { - req, err := http.NewRequest(http.MethodGet, "/", nil) - assert.NoError(err, tcID) - - rr := httptest.NewRecorder() - handler := IndexViewHandler() - - handler.ServeHTTP(rr, req) - - assert.Equal(tc.expectedStatusCode, rr.Code, tcID) - assert.Contains(rr.Body.String(), tc.expectedBodyContains, tcID) - } -} diff --git a/main.go b/main.go index de32c91..b252586 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { Methods(http.MethodGet). Path("/"). Handler(adapters.Adapt( - IndexViewHandler(), + http.RedirectHandler("/buckets", http.StatusPermanentRedirect), logging.Handler(logger), )) r.