Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7dd0a8

Browse filesBrowse files
author
anonx
committed
Add NewTestRequest method to close revel#791
1 parent 311cff9 commit f7dd0a8
Copy full SHA for f7dd0a8

File tree

1 file changed

+23
-20
lines changed
Filter options

1 file changed

+23
-20
lines changed

‎testing/testsuite.go

Copy file name to clipboardExpand all lines: testing/testsuite.go
+23-20Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ func NewTestSuite() TestSuite {
4545
}
4646
}
4747

48+
// NewTestRequest returns an initialized *TestRequest. It is used for extending
49+
// testsuite package making it possibe to define own methods. Example:
50+
// type MyTestSuite struct {
51+
// testing.TestSuite
52+
// }
53+
//
54+
// func (t *MyTestSuite) PutFormCustom(...) {
55+
// req := http.NewRequest(...)
56+
// ...
57+
// return t.NewTestRequest(req)
58+
// }
59+
func (t *TestSuite) NewTestRequest(req *http.Request) *TestRequest {
60+
return &TestRequest{
61+
Request: req,
62+
testSuite: t,
63+
}
64+
}
65+
4866
// Return the address and port of the server, e.g. "127.0.0.1:8557"
4967
func (t *TestSuite) Host() string {
5068
if revel.Server.Addr[0] == ':' {
@@ -80,10 +98,7 @@ func (t *TestSuite) GetCustom(uri string) *TestRequest {
8098
if err != nil {
8199
panic(err)
82100
}
83-
return &TestRequest{
84-
Request: req,
85-
testSuite: t,
86-
}
101+
return t.NewTestRequest(req)
87102
}
88103

89104
// Issue a DELETE request to the given path and store the result in Response and
@@ -98,10 +113,7 @@ func (t *TestSuite) DeleteCustom(uri string) *TestRequest {
98113
if err != nil {
99114
panic(err)
100115
}
101-
return &TestRequest{
102-
Request: req,
103-
testSuite: t,
104-
}
116+
return t.NewTestRequest(req)
105117
}
106118

107119
// Issue a PUT request to the given path, sending the given Content-Type and
@@ -118,10 +130,7 @@ func (t *TestSuite) PutCustom(uri string, contentType string, reader io.Reader)
118130
panic(err)
119131
}
120132
req.Header.Set("Content-Type", contentType)
121-
return &TestRequest{
122-
Request: req,
123-
testSuite: t,
124-
}
133+
return t.NewTestRequest(req)
125134
}
126135

127136
// Issue a PATCH request to the given path, sending the given Content-Type and
@@ -138,10 +147,7 @@ func (t *TestSuite) PatchCustom(uri string, contentType string, reader io.Reader
138147
panic(err)
139148
}
140149
req.Header.Set("Content-Type", contentType)
141-
return &TestRequest{
142-
Request: req,
143-
testSuite: t,
144-
}
150+
return t.NewTestRequest(req)
145151
}
146152

147153
// Issue a POST request to the given path, sending the given Content-Type and
@@ -158,10 +164,7 @@ func (t *TestSuite) PostCustom(uri string, contentType string, reader io.Reader)
158164
panic(err)
159165
}
160166
req.Header.Set("Content-Type", contentType)
161-
return &TestRequest{
162-
Request: req,
163-
testSuite: t,
164-
}
167+
return t.NewTestRequest(req)
165168
}
166169

167170
// Issue a POST request to the given path as a form post of the given key and

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.