-
Notifications
You must be signed in to change notification settings - Fork 19
/
context_test.go
51 lines (40 loc) · 1.05 KB
/
context_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
package gongular
import (
"io/ioutil"
"log"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestContext_Fail(t *testing.T) {
c := Context{}
c.Fail(http.StatusBadRequest, "hello world")
assert.Equal(t, c.status, http.StatusBadRequest)
assert.Equal(t, c.body, "hello world")
}
func TestContext_Header(t *testing.T) {
c := Context{}
c.headers = make(map[string]string)
c.Header("Content-type", "application/json")
assert.Equal(t, c.headers["Content-type"], "application/json")
}
func TestContext_Request(t *testing.T) {
c := Context{}
req := &http.Request{}
c.r = req
assert.Equal(t, req, c.Request())
}
func TestContext_Status(t *testing.T) {
c := Context{}
c.Status(http.StatusTeapot)
assert.Equal(t, http.StatusTeapot, c.status)
}
func TestContext_StatusTwice(t *testing.T) {
c := Context{}
// TODO: Remove logger
c.logger = log.New(ioutil.Discard, "", 0)
c.Status(http.StatusTeapot)
assert.Equal(t, http.StatusTeapot, c.status)
c.Status(http.StatusInternalServerError)
assert.Equal(t, http.StatusTeapot, c.status)
}