Fudge

fudge / handler / handler_test.go

Commits | bovarysme Release v0.4.0 Committed on Dec 25, 2019

854 B | Download

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package handler

import (
	"net/http"
	"net/http/httptest"
	"os"
	"strings"
	"testing"

	"bovarys.me/fudge/config"
)

func init() {
	err := os.Chdir("..")
	if err != nil {
		panic(err)
	}
}

func TestRepositoryNotFound(t *testing.T) {
	cfg := &config.Config{
		RepoRoot: "../",
		Debug:    true,
	}

	h, err := NewHandler(cfg)
	if err != nil {
		t.Fatal(err)
	}

	request, err := http.NewRequest("GET", "/notfound", nil)
	if err != nil {
		t.Fatal(err)
	}

	recorder := httptest.NewRecorder()

	handler := http.HandlerFunc(h.showTree)
	handler.ServeHTTP(recorder, request)

	status := recorder.Code
	if status != http.StatusNotFound {
		t.Errorf("wrong status code: got %v want %v", status, http.StatusNotFound)
	}

	body := recorder.Body.String()
	if !strings.Contains(body, "Page not found") {
		t.Error("body does not contains 'Page not found'")
	}
}