-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
expect_test.go
61 lines (52 loc) · 1.17 KB
/
expect_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
53
54
55
56
57
58
59
60
61
package hit_test
import (
"testing"
"github.com/stretchr/testify/require"
. "github.com/Eun/go-hit"
)
func TestExpect_Custom(t *testing.T) {
s := EchoServer()
defer s.Close()
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Custom(func(hit Hit) error {
require.Equal(t, "Hello World", hit.Response().Body().MustString())
return nil
}),
)
}
func TestExpect_Double(t *testing.T) {
s := EchoServer()
defer s.Close()
Test(t,
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Body().String().Equal(`Hello World`),
Expect().Body().String().Equal(`Hello World`),
)
}
func TestExpect_DeepFunc(t *testing.T) {
s := EchoServer()
defer s.Close()
calledFunc := false
ExpectError(t,
Do(
Post(s.URL),
Send().Body().String("Hello World"),
Expect().Custom(func(h1 Hit) error {
h1.MustDo(Expect().Custom(func(h2 Hit) error {
h2.MustDo(Expect().Custom(func(h3 Hit) error {
calledFunc = true
h3.MustDo(Expect().Body().String().Equal("Hello Universe"))
return nil
}))
return nil
}))
return nil
}),
),
PtrStr("not equal"), nil, nil, nil, nil, nil, nil,
)
require.True(t, calledFunc)
}