-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_test.go
50 lines (39 loc) · 1.06 KB
/
base_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
package main
import (
"io/ioutil"
"net/http/httptest"
"os"
"testing"
"time"
)
var a int = 4
var b int = 2
// Execute before and after suit test
func TestMain(m *testing.M) {
go createWebserver()
sleep()
code := m.Run()
os.Exit(code)
}
//check the body content of a response
func checkContent(t *testing.T, response *httptest.ResponseRecorder, content string) {
body, _ := ioutil.ReadAll(response.Body)
if string(body) != content {
t.Fatalf("Non-expected content %s, expected %s", string(body), content)
}
}
//Check the status code
func checkStatus(t *testing.T, response *httptest.ResponseRecorder, expected int) {
if response.Code != expected {
t.Fatalf("Non-expected status code %v :\n\tbody: %v", expected, response.Code)
}
}
//Check the specific header value
func checkHeader(t *testing.T, response *httptest.ResponseRecorder, header string, value string) {
if response.Header().Get(header) != value {
t.Fatalf("Header: %s, get:%s expected:%s", header, response.Header().Get(header), value)
}
}
func sleep() {
time.Sleep(500 * time.Millisecond)
}