-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_test.go
43 lines (33 loc) · 840 Bytes
/
mock_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
package web_test
import (
"testing"
"github.com/ecnepsnai/web"
)
func TestMock(t *testing.T) {
type exampleType struct {
Enabled bool
}
userData := 1
handle := func(request web.Request) (interface{}, *web.Error) {
example := exampleType{}
if err := request.DecodeJSON(&example); err != nil {
t.Error("Error decoding example JSON object from mocked request")
}
if !example.Enabled {
t.Error("Invalid HTTP body from mocked request")
}
if request.UserData.(int) != userData {
t.Error("Invalid user data")
}
if request.Parameters["foo"] != "bar" {
t.Error("Invalid request path parameters")
}
return nil, nil
}
request := web.MockRequest(web.MockRequestParameters{
UserData: userData,
Parameters: map[string]string{"foo": "bar"},
JSONBody: exampleType{true},
})
handle(request)
}