This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_test.go
123 lines (105 loc) · 2.8 KB
/
response_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package geyser_test
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/13k/geyser/v2"
"github.com/13k/geyser/v2/schema"
)
func TestResponse_Getters(t *testing.T) {
assert := assert.New(t)
res := &geyser.Response{}
assert.Nil(res.Header())
assert.Nil(res.Cookies())
assert.Equal("", res.Status())
assert.Equal(0, res.StatusCode())
assert.False(res.IsError())
assert.False(res.IsSuccess())
assert.Nil(res.Result())
assert.Equal(time.Duration(0), res.Duration())
si := &schema.Interface{}
sm := &schema.Method{}
result := map[string]interface{}{}
req := geyser.NewRequest(si, sm).SetResult(result)
res = &geyser.Response{
Request: req,
}
assert.Nil(res.Header())
assert.Nil(res.Cookies())
assert.Equal("", res.Status())
assert.Equal(0, res.StatusCode())
assert.False(res.IsError())
assert.False(res.IsSuccess())
assert.Exactly(result, res.Result())
assert.Equal(time.Duration(0), res.Duration())
header := http.Header{"X-Test": {"test"}}
res = &geyser.Response{
Request: req,
Raw: &http.Response{
Header: header,
Status: "299 Test OK",
StatusCode: 299,
},
}
assert.Equal(header, res.Header())
assert.Empty(res.Cookies())
assert.False(res.IsError())
assert.True(res.IsSuccess())
assert.Equal("299 Test OK", res.Status())
assert.Equal(299, res.StatusCode())
assert.Exactly(result, res.Result())
assert.Equal(time.Duration(0), res.Duration())
res = &geyser.Response{
Request: req,
Raw: &http.Response{
Header: header,
Status: "400 Test Error",
StatusCode: 400,
},
}
assert.Equal(header, res.Header())
assert.Empty(res.Cookies())
assert.True(res.IsError())
assert.False(res.IsSuccess())
assert.Equal("400 Test Error", res.Status())
assert.Equal(400, res.StatusCode())
assert.Exactly(result, res.Result())
assert.Equal(time.Duration(0), res.Duration())
now := time.Now()
res = &geyser.Response{
Request: req,
Raw: &http.Response{
Header: header,
Status: "400 Test Error",
StatusCode: 400,
},
Time: now,
}
assert.Equal(header, res.Header())
assert.Empty(res.Cookies())
assert.True(res.IsError())
assert.False(res.IsSuccess())
assert.Equal("400 Test Error", res.Status())
assert.Equal(400, res.StatusCode())
assert.Exactly(result, res.Result())
assert.Equal(time.Duration(0), res.Duration())
req.Time = now.Add(-13 * time.Second)
res = &geyser.Response{
Request: req,
Raw: &http.Response{
Header: header,
Status: "400 Test Error",
StatusCode: 400,
},
Time: now,
}
assert.Equal(header, res.Header())
assert.Empty(res.Cookies())
assert.True(res.IsError())
assert.False(res.IsSuccess())
assert.Equal("400 Test Error", res.Status())
assert.Equal(400, res.StatusCode())
assert.Exactly(result, res.Result())
assert.Equal(13*time.Second, res.Duration())
}