summaryrefslogtreecommitdiff
path: root/app/handler_test.go
blob: 67692b03ea39ca509d88a974ef4f33af09560ac4 (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
// +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)
	}
}