-
Notifications
You must be signed in to change notification settings - Fork 1
/
caas_test.go
52 lines (37 loc) · 1.1 KB
/
caas_test.go
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
51
52
package main
import (
_"encoding/json"
_"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestHello(t *testing.T) {
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()
hello(response, request)
if response.Code != http.StatusOK {
t.Fatalf("Non-expected status code%v:\n\tbody: %v", "200", response.Code)
}
assert.Equal(t, "Hello world!", response.Body.String())
}
func TestCatReturnsJSON(t *testing.T) {
request, _ := http.NewRequest("GET", "/cat", nil)
response := httptest.NewRecorder()
cat(response, request)
ct := response.HeaderMap["Content-Type"][0]
if !strings.EqualFold(ct, "application/json") {
t.Fatalf("Content-Type does not equal 'application/json'")
}
}
func TestCatpic(t *testing.T) {
request, _ := http.NewRequest("GET", "/catpic", nil)
response := httptest.NewRecorder()
catpic(response, request)
if response.Code != http.StatusOK {
t.Fatalf("Non-expected status code%v:\n\tbody: %v", "200", response.Code)
}
assert.Contains(t, response.Body.String(), "img src=")
}