@@ -63,15 +63,15 @@ func (t *TestSuite) NewTestRequest(req *http.Request) *TestRequest {
63
63
}
64
64
}
65
65
66
- // Return the address and port of the server, e.g. "127.0.0.1:8557"
66
+ // Host returns the address and port of the server, e.g. "127.0.0.1:8557"
67
67
func (t * TestSuite ) Host () string {
68
68
if revel .Server .Addr [0 ] == ':' {
69
69
return "127.0.0.1" + revel .Server .Addr
70
70
}
71
71
return revel .Server .Addr
72
72
}
73
73
74
- // Return the base http/https URL of the server, e.g. "http://127.0.0.1:8557".
74
+ // BaseUrl returns the base http/https URL of the server, e.g. "http://127.0.0.1:8557".
75
75
// The scheme is set to https if http.ssl is set to true in the configuration file.
76
76
func (t * TestSuite ) BaseUrl () string {
77
77
if revel .HTTPSsl {
@@ -80,18 +80,18 @@ func (t *TestSuite) BaseUrl() string {
80
80
return "http://" + t .Host ()
81
81
}
82
82
83
- // Return the base websocket URL of the server, e.g. "ws://127.0.0.1:8557"
83
+ // WebSocketUrl returns the base websocket URL of the server, e.g. "ws://127.0.0.1:8557"
84
84
func (t * TestSuite ) WebSocketUrl () string {
85
85
return "ws://" + t .Host ()
86
86
}
87
87
88
- // Issue a GET request to the given path and store the result in Response and
89
- // ResponseBody.
88
+ // Get issues a GET request to the given path and stores the result in Response
89
+ // and ResponseBody.
90
90
func (t * TestSuite ) Get (path string ) {
91
91
t .GetCustom (t .BaseUrl () + path ).Send ()
92
92
}
93
93
94
- // Return a GET request to the given uri in a form of its wrapper.
94
+ // GetCustom returns a GET request to the given URI in a form of its wrapper.
95
95
func (t * TestSuite ) GetCustom (uri string ) * TestRequest {
96
96
req , err := http .NewRequest ("GET" , uri , nil )
97
97
if err != nil {
@@ -100,13 +100,14 @@ func (t *TestSuite) GetCustom(uri string) *TestRequest {
100
100
return t .NewTestRequest (req )
101
101
}
102
102
103
- // Issue a DELETE request to the given path and store the result in Response and
104
- // ResponseBody.
103
+ // Delete issues a DELETE request to the given path and stores the result in
104
+ // Response and ResponseBody.
105
105
func (t * TestSuite ) Delete (path string ) {
106
106
t .DeleteCustom (t .BaseUrl () + path ).Send ()
107
107
}
108
108
109
- // Return a DELETE request to the given uri in a form of its wrapper.
109
+ // DeleteCustom returns a DELETE request to the given URI in a form of its
110
+ // wrapper.
110
111
func (t * TestSuite ) DeleteCustom (uri string ) * TestRequest {
111
112
req , err := http .NewRequest ("DELETE" , uri , nil )
112
113
if err != nil {
@@ -115,14 +116,14 @@ func (t *TestSuite) DeleteCustom(uri string) *TestRequest {
115
116
return t .NewTestRequest (req )
116
117
}
117
118
118
- // Issue a PUT request to the given path, sending the given Content-Type and
119
- // data, and store the result in Response and ResponseBody. "data" may be nil.
119
+ // Put issues a PUT request to the given path, sending the given Content-Type
120
+ // and data, storing the result in Response and ResponseBody. "data" may be nil.
120
121
func (t * TestSuite ) Put (path string , contentType string , reader io.Reader ) {
121
122
t .PutCustom (t .BaseUrl ()+ path , contentType , reader ).Send ()
122
123
}
123
124
124
- // Return a PUT request to the given uri with specified Content-Type and data
125
- // in a form of wrapper. "data" may be nil.
125
+ // PutCustom returns a PUT request to the given URI with specified Content-Type
126
+ // and data in a form of wrapper. "data" may be nil.
126
127
func (t * TestSuite ) PutCustom (uri string , contentType string , reader io.Reader ) * TestRequest {
127
128
req , err := http .NewRequest ("PUT" , uri , reader )
128
129
if err != nil {
@@ -132,26 +133,27 @@ func (t *TestSuite) PutCustom(uri string, contentType string, reader io.Reader)
132
133
return t .NewTestRequest (req )
133
134
}
134
135
135
- // Issue a PUT request to the given path as a form put of the given key and
136
- // values, and store the result in Response and ResponseBody.
136
+ // PutForm issues a PUT request to the given path as a form put of the given key
137
+ // and values, and stores the result in Response and ResponseBody.
137
138
func (t * TestSuite ) PutForm (path string , data url.Values ) {
138
139
t .PutFormCustom (t .BaseUrl ()+ path , data ).Send ()
139
140
}
140
141
141
- // Return a PUT request to the given uri as a form put of the given key and values.
142
- // The request is in a form of TestRequest wrapper.
142
+ // PutFormCustom returns a PUT request to the given URI as a form put of the
143
+ // given key and values. The request is in a form of TestRequest wrapper.
143
144
func (t * TestSuite ) PutFormCustom (uri string , data url.Values ) * TestRequest {
144
145
return t .PutCustom (uri , "application/x-www-form-urlencoded" , strings .NewReader (data .Encode ()))
145
146
}
146
147
147
- // Issue a PATCH request to the given path, sending the given Content-Type and
148
- // data, and store the result in Response and ResponseBody. "data" may be nil.
148
+ // Patch issues a PATCH request to the given path, sending the given
149
+ // Content-Type and data, and stores the result in Response and ResponseBody.
150
+ // "data" may be nil.
149
151
func (t * TestSuite ) Patch (path string , contentType string , reader io.Reader ) {
150
152
t .PatchCustom (t .BaseUrl ()+ path , contentType , reader ).Send ()
151
153
}
152
154
153
- // Return a PATCH request to the given uri with specified Content-Type and data
154
- // in a form of wrapper. "data" may be nil.
155
+ // PatchCustom returns a PATCH request to the given URI with specified
156
+ // Content-Type and data in a form of wrapper. "data" may be nil.
155
157
func (t * TestSuite ) PatchCustom (uri string , contentType string , reader io.Reader ) * TestRequest {
156
158
req , err := http .NewRequest ("PATCH" , uri , reader )
157
159
if err != nil {
@@ -161,14 +163,14 @@ func (t *TestSuite) PatchCustom(uri string, contentType string, reader io.Reader
161
163
return t .NewTestRequest (req )
162
164
}
163
165
164
- // Issue a POST request to the given path, sending the given Content-Type and
165
- // data, and store the result in Response and ResponseBody. "data" may be nil.
166
+ // Post issues a POST request to the given path, sending the given Content-Type
167
+ // and data, storing the result in Response and ResponseBody. "data" may be nil.
166
168
func (t * TestSuite ) Post (path string , contentType string , reader io.Reader ) {
167
169
t .PostCustom (t .BaseUrl ()+ path , contentType , reader ).Send ()
168
170
}
169
171
170
- // Return a POST request to the given uri with specified Content-Type and data
171
- // in a form of wrapper. "data" may be nil.
172
+ // PostCustom returns a POST request to the given URI with specified
173
+ // Content-Type and data in a form of wrapper. "data" may be nil.
172
174
func (t * TestSuite ) PostCustom (uri string , contentType string , reader io.Reader ) * TestRequest {
173
175
req , err := http .NewRequest ("POST" , uri , reader )
174
176
if err != nil {
@@ -178,26 +180,26 @@ func (t *TestSuite) PostCustom(uri string, contentType string, reader io.Reader)
178
180
return t .NewTestRequest (req )
179
181
}
180
182
181
- // Issue a POST request to the given path as a form post of the given key and
182
- // values, and store the result in Response and ResponseBody.
183
+ // PostForm issues a POST request to the given path as a form post of the given
184
+ // key and values, and stores the result in Response and ResponseBody.
183
185
func (t * TestSuite ) PostForm (path string , data url.Values ) {
184
186
t .PostFormCustom (t .BaseUrl ()+ path , data ).Send ()
185
187
}
186
188
187
- // Return a POST request to the given uri as a form post of the given key and values.
188
- // The request is in a form of TestRequest wrapper.
189
+ // PostFormCustom returns a POST request to the given URI as a form post of the
190
+ // given key and values. The request is in a form of TestRequest wrapper.
189
191
func (t * TestSuite ) PostFormCustom (uri string , data url.Values ) * TestRequest {
190
192
return t .PostCustom (uri , "application/x-www-form-urlencoded" , strings .NewReader (data .Encode ()))
191
193
}
192
194
193
- // Issue a multipart request to the given path sending given params and files,
194
- // and store the result in Response and ResponseBody.
195
+ // PostFile issues a multipart request to the given path sending given params
196
+ // and files, and stores the result in Response and ResponseBody.
195
197
func (t * TestSuite ) PostFile (path string , params url.Values , filePaths url.Values ) {
196
198
t .PostFileCustom (t .BaseUrl ()+ path , params , filePaths ).Send ()
197
199
}
198
200
199
- // Return a multipart request to the given uri in a form of its wrapper
200
- // with the given params and files.
201
+ // PostFileCustom returns a multipart request to the given URI in a form of its
202
+ // wrapper with the given params and files.
201
203
func (t * TestSuite ) PostFileCustom (uri string , params url.Values , filePaths url.Values ) * TestRequest {
202
204
body := & bytes.Buffer {}
203
205
writer := multipart .NewWriter (body )
@@ -220,16 +222,16 @@ func (t *TestSuite) PostFileCustom(uri string, params url.Values, filePaths url.
220
222
return t .PostCustom (uri , writer .FormDataContentType (), body )
221
223
}
222
224
223
- // Issue any request and read the response. If successful, the caller may
225
+ // Send issues any request and reads the response. If successful, the caller may
224
226
// examine the Response and ResponseBody properties. Session data will be
225
227
// added to the request cookies for you.
226
228
func (r * TestRequest ) Send () {
227
229
r .AddCookie (r .testSuite .Session .Cookie ())
228
230
r .MakeRequest ()
229
231
}
230
232
231
- // Issue any request and read the response. If successful, the caller may
232
- // examine the Response and ResponseBody properties. You will need to
233
+ // MakeRequest issues any request and read the response. If successful, the
234
+ // caller may examine the Response and ResponseBody properties. You will need to
233
235
// manage session / cookie data manually
234
236
func (r * TestRequest ) MakeRequest () {
235
237
var err error
@@ -250,7 +252,7 @@ func (r *TestRequest) MakeRequest() {
250
252
}
251
253
}
252
254
253
- // Create a websocket connection to the given path and return the connection
255
+ // WebSocket creates a websocket connection to the given path and returns it
254
256
func (t * TestSuite ) WebSocket (path string ) * websocket.Conn {
255
257
origin := t .BaseUrl () + "/"
256
258
url := t .WebSocketUrl () + path
@@ -308,21 +310,21 @@ func (t *TestSuite) Assertf(exp bool, formatStr string, args ...interface{}) {
308
310
}
309
311
}
310
312
311
- // Assert that the response contains the given string.
313
+ // AssertContains asserts that the response contains the given string.
312
314
func (t * TestSuite ) AssertContains (s string ) {
313
315
if ! bytes .Contains (t .ResponseBody , []byte (s )) {
314
316
panic (fmt .Errorf ("Assertion failed. Expected response to contain %s" , s ))
315
317
}
316
318
}
317
319
318
- // Assert that the response does not contain the given string.
320
+ // AssertNotContains asserts that the response does not contain the given string.
319
321
func (t * TestSuite ) AssertNotContains (s string ) {
320
322
if bytes .Contains (t .ResponseBody , []byte (s )) {
321
323
panic (fmt .Errorf ("Assertion failed. Expected response not to contain %s" , s ))
322
324
}
323
325
}
324
326
325
- // Assert that the response matches the given regular expression.
327
+ // AssertContainsRegex asserts that the response matches the given regular expression.
326
328
func (t * TestSuite ) AssertContainsRegex (regex string ) {
327
329
r := regexp .MustCompile (regex )
328
330
0 commit comments