summaryrefslogtreecommitdiff
path: root/app/handler_test.go
blob: 53d8775dbc068cd155c811d9aeb2952ea08180ee (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build all dep

package main

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

func TestIndexHandler(t *testing.T) {
	request, err := http.NewRequest("GET", "/", nil)
	if err != nil {
		t.Log("Error creating new http request. ", err)
	}
	response := httptest.NewRecorder()

	IndexHandler(response, request)

	if response.Code != 200 {
		t.Log(response.Code)
		t.Fatal("Expected 200 as status code.")
	}
}

func BenchmarkIndexHandler(b *testing.B) {
	b.StopTimer()
	request, _ := http.NewRequest("GET", "/", nil)
	response := httptest.NewRecorder()

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		IndexHandler(response, request)
	}
}

func TestAdminHandler(t *testing.T) {
	request, err := http.NewRequest("GET", "/admin", nil)
	if err != nil {
		t.Log("Error creating new http request. ", err)
	}
	response := httptest.NewRecorder()

	AdminHandler(response, request)

	if response.Code != 302 {
		t.Log(response.Code)
		t.Fatal("Expected 403 as status code.")
	}
}