From 907bd7e63f4cf3cb01bc678e09fc5b8962afe750 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 11 May 2024 23:08:42 +0200 Subject: view: Add unit test for index handler --- view/index_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 view/index_test.go (limited to 'view') diff --git a/view/index_test.go b/view/index_test.go new file mode 100644 index 0000000..583032c --- /dev/null +++ b/view/index_test.go @@ -0,0 +1,31 @@ +package view + +import ( + "testing" + "net/http" + "net/http/httptest" +) + +func TestIndexRead(t *testing.T) { + req, err := http.NewRequest("GET", "/", nil) + if err != nil { + t.Fatal(err) + } + + rec := httptest.NewRecorder() + + handler := http.HandlerFunc(IndexRead) + handler.ServeHTTP(rec, req) + + if rec.Code != http.StatusSeeOther { + t.Errorf("Wrong status code: got %v want %v", rec.Code, http.StatusOK) + } + + expected := `See Other. + +` + if rec.Body.String() != expected { + t.Errorf("Wrong response body: got '%v' want '%v'", + rec.Body.String(), expected) + } +} -- cgit v1.2.3-70-g09d2