From ea860a0790f00b9da9bfef895a5d58760a334b49 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 30 Sep 2020 16:09:25 +0200 Subject: [PATCH] More coverage on web package --- web/handler.go | 2 +- web/handler_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/web/handler.go b/web/handler.go index e3e0afa..3537b01 100644 --- a/web/handler.go +++ b/web/handler.go @@ -36,7 +36,7 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "application/json") - w.Write(jsonDesc) + _, _ = w.Write(jsonDesc) // Increment monitoring monitoring.WebSessions.Inc() diff --git a/web/handler_test.go b/web/handler_test.go index 58c1db2..064e70a 100644 --- a/web/handler_test.go +++ b/web/handler_test.go @@ -19,4 +19,20 @@ func TestViewerPageGET(t *testing.T) { if w.Code != http.StatusOK { t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK) } + + // Test GET request on not found page + r, _ = http.NewRequest("GET", "", nil) + w = httptest.NewRecorder() + http.HandlerFunc(viewerHandler).ServeHTTP(w, r) + if w.Code != http.StatusNotFound { + t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK) + } + + // Test GET request on statistics page + r, _ = http.NewRequest("GET", "/", nil) + w = httptest.NewRecorder() + http.HandlerFunc(statisticsHandler).ServeHTTP(w, r) + if w.Code != http.StatusOK { + t.Errorf("Viewer page returned %v != %v on GET", w.Code, http.StatusOK) + } }