summaryrefslogtreecommitdiff
path: root/view/index_test.go
blob: 68167f6d76d16acdf10ab70a79e21d2f185073d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package view

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestIndexRead(t *testing.T) {
	req, err := http.NewRequest("GET", "/", nil)
	if err != nil {
		t.Fatal(err)
	}

	rec := httptest.NewRecorder()

	handler := 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)
	}
}