-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrequest_data_test.go
More file actions
109 lines (91 loc) · 2.44 KB
/
request_data_test.go
File metadata and controls
109 lines (91 loc) · 2.44 KB
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
package raygun4go
import (
"errors"
"net/http"
"net/url"
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestRequestData(t *testing.T) {
Convey("#NewRequestData", t, func() {
u := "http://www.example.com?foo=bar&fizz[]=buzz&fizz[]=buzz2"
r, _ := http.NewRequest("GET", u, nil)
Convey("empty if no request given", func() {
d := newRequestData(nil)
So(d, ShouldResemble, RequestData{})
})
Convey("basic data", func() {
r.RemoteAddr = "1.2.3.4"
d := newRequestData(r)
So(d.HostName, ShouldEqual, "www.example.com")
So(d.URL, ShouldEqual, u)
So(d.HTTPMethod, ShouldEqual, "GET")
So(d.IPAddress, ShouldResemble, "1.2.3.4")
})
Convey("Form", func() {
r.PostForm = url.Values{
"foo": []string{"bar"},
"fizz": []string{"buzz", "buzz2"},
}
expected := map[string]string{
"foo": "bar",
"fizz": "[buzz; buzz2]",
}
d := newRequestData(r)
So(d.Form, ShouldResemble, expected)
})
Convey("QueryString", func() {
expected := map[string]string{
"foo": "bar",
"fizz[]": "[buzz; buzz2]",
}
d := newRequestData(r)
So(d.QueryString, ShouldResemble, expected)
})
Convey("Headers", func() {
r.Header = map[string][]string{
"foo": {"bar"},
"fizz": {"buzz"},
}
expected := map[string]string{
"foo": "bar",
"fizz": "buzz",
}
d := newRequestData(r)
So(d.Headers, ShouldResemble, expected)
})
})
}
func TestErrorData(t *testing.T) {
Convey("#NewErrorData", t, func() {
trace, _ := os.ReadFile("_fixtures/stack_trace")
e := errors.New("test error")
stack := make(StackTrace, 0)
Parse(trace, &stack)
d := newErrorData(e, stack[3:])
expected := StackTrace{
StackTraceElement{78, "github.com/smartystreets/goconvey/convey", "scope.go", "(*scope).visitNextChild(0x208326090, 0x2082d26c0)"},
StackTraceElement{71, "github.com/smartystreets/goconvey/convey", "scope.go", "(*scope).visit(0x208326090, 0x2082d26c0)"},
}
So(d.Message, ShouldEqual, "test error")
So(d.StackTrace[0], ShouldResemble, expected[0])
So(d.StackTrace[1], ShouldResemble, expected[1])
})
}
func TestUser(t *testing.T) {
Convey("has an exported identifier", t, func() {
u := User{"test"}
So(u.Identifier, ShouldEqual, "test")
})
}
func TestContext(t *testing.T) {
Convey("has an exported identifier", t, func() {
c := Context{"test"}
So(c.Identifier, ShouldEqual, "test")
})
}
func Test(t *testing.T) {
Convey("", t, func() {
})
}