-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtest_helper_test.go
47 lines (33 loc) · 1.09 KB
/
test_helper_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
package goweb
import (
"github.com/stretchr/codecs/services"
"github.com/stretchr/goweb/context"
"github.com/stretchr/goweb/handlers"
"github.com/stretchr/testify/assert"
testifyhttp "github.com/stretchr/testify/http"
"testing"
)
func TestTestFunc(t *testing.T) {
// keep track of things that occur
var actualT *testing.T
var called bool = false
// setup test objects
testingObj := new(testing.T)
// map something to a handler
testCodecService := new(services.WebCodecService)
handler := handlers.NewHttpHandler(testCodecService)
// map the target method
handler.Map("GET", "people/{id}", func(ctx context.Context) error {
return Respond.With(ctx, 201, []byte("Hello Goweb"))
})
// call the target method
TestOn(testingObj, handler, "GET people/123", func(passedT *testing.T, response *testifyhttp.TestResponseWriter) {
called = true
// save the passed in T object
actualT = passedT
})
if assert.True(t, called, "The assertion method should be called.") {
// make assertions about what happened
assert.Equal(t, actualT, testingObj, "Passed in T wasn't right")
}
}