diff options
author | xengineering <me@xengineering.eu> | 2024-05-11 23:08:42 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-11 23:08:42 +0200 |
commit | 907bd7e63f4cf3cb01bc678e09fc5b8962afe750 (patch) | |
tree | a969d945daa6a1868b6c602a4d4abfb01b6dd942 | |
parent | 0ac3cc76b4b6c824c4b3f7a357d40b487984abfb (diff) | |
download | ceres-907bd7e63f4cf3cb01bc678e09fc5b8962afe750.tar ceres-907bd7e63f4cf3cb01bc678e09fc5b8962afe750.tar.zst ceres-907bd7e63f4cf3cb01bc678e09fc5b8962afe750.zip |
view: Add unit test for index handler
-rw-r--r-- | view/index_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
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 := `<a href="/recipes">See Other</a>. + +` + if rec.Body.String() != expected { + t.Errorf("Wrong response body: got '%v' want '%v'", + rec.Body.String(), expected) + } +} |