You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But this is where we have to stop and consider what we mean by the expected response being
147
147
equal to the actual response.
148
148
149
+
## Headers
150
+
149
151
### Header Case
150
152
151
-
The HTTP spec states that we should treat the header "content-type: text/html" to be equivilent to
152
-
the header "Content-type: text/html"
153
+
The HTTP spec states that we should treat the header `content-type: text/html` to be equivalent to
154
+
the header `Content-type: text/html`
153
155
154
156
### Header Whitespace
155
157
156
-
The HTTP spec also states that the header "Content-type: text/html" is equivilent to the header
157
-
"Content-type: test/html ". i.e. additional whitespace is ignored
158
+
The HTTP spec also states that the header `Content-type: text/html` is equivalent to the header
159
+
`Content-type: text/html `. i.e. additional whitespace is ignored
158
160
159
161
### Cache-Control Header and Parameter Order
160
162
161
-
Another thing the spec says is that "Cache-Control: max-age=3600, no-store" is equivilent to
162
-
"Cache-Control: no-store, max-age=3600".
163
+
Another thing the spec says is that `Cache-Control: max-age=3600, no-store` is equivalent to
164
+
`Cache-Control: no-store, max-age=3600`.
163
165
164
-
If your expected response is "Cache-Control: max-age=3600, no-store", but the actual response
165
-
is "Cache-Control: no-store, max-age=3600" you want to say that that expected header matches.
166
+
If your expected response is `Cache-Control: max-age=3600, no-store`, but the actual response
167
+
is `Cache-Control: no-store, max-age=3600` you want to say that that expected header matches.
166
168
167
169
But that there are some headers where the order is important, e.g.
168
-
"Content-Encoding: sdch, gzip". The order matters, and cannot be reversed.
170
+
`Content-Encoding: sdch, gzip`. The order matters, and cannot be reversed.
169
171
170
172
### Date Header
171
173
@@ -178,23 +180,23 @@ where you want the header to be present, but you don't care about the value
178
180
179
181
### X-Request-ID Header
180
182
181
-
There are some headers that may be added the server code, or by middleware, or even
182
-
by intermediate proxies. "X-Request-ID" is one of these, and we may want to ignore it
183
+
There are some headers that may be added by the server code, or by middleware, or even
184
+
by intermediate proxies. `X-Request-ID` is one of these, and we may want to ignore it
183
185
altogether, or simply validate that the header is present, while ignoring the
184
186
value.
185
187
186
-
"Via: 1.1 varnish" is explicitly a proxy header, and may be added by intermediate hops
188
+
`Via: 1.1 varnish` is explicitly a proxy header, and may be added by intermediate hops
187
189
in the HTTP request when running in the real world.
188
190
189
191
190
192
## JSON Response Body
191
193
192
-
The JSON body itself can be strucurally equivilent, but not be exactly the same.
194
+
The JSON body itself can be structurally equivalent, but not be exactly the same.
193
195
194
196
### Whitespace
195
197
196
-
`{"Username":"joeblogs"}` is strucurally equivilent to `{ "Username": "joeblogs" }`
197
-
which is also equivilent to
198
+
`{"Username":"joeblogs"}` is structurally equivalent to `{ "Username": "joeblogs" }`
199
+
which is also equivalent to
198
200
199
201
```
200
202
{
@@ -211,7 +213,7 @@ which is also equivilent to
211
213
}
212
214
```
213
215
214
-
is strucrally equivilent to
216
+
is structurally equivalent to
215
217
216
218
```
217
219
{
@@ -220,29 +222,33 @@ is strucrally equivilent to
220
222
}
221
223
```
222
224
223
-
### Numerical Equivilence
225
+
### Numerical Equivalence
226
+
227
+
TODO
224
228
225
229
1 ≡ 1.0 ≡ 1e0
226
230
227
231
228
-
### Escaped Equivilence
232
+
### Escaped Equivalence
233
+
234
+
TODO
229
235
230
236
"hello" ≡ "he\u006Clo"
231
237
232
238
233
239
## Selective Field Testing, Field Presence Only
234
240
235
241
Sometimes, when testing a specific action with an API, we may not care about all of
236
-
the feilds, but only the ones that are relevant to the action we are performing.
242
+
the fields, but only the ones that are relevant to the action we are performing.
237
243
238
244
Another common case is that we want to ensure that a certain field is present, but we don't
239
245
care what the value is. E.g. when creating a new entity.
240
246
241
-
For example a POST call to /api/job,
242
-
where we care that we get a reponse back with the job details, but every call to the API
247
+
For example a POST call to /api/job,
248
+
where we care that we get a response back with the job details, but every call to the API
243
249
will give us a unique job ID.
244
250
245
-
This is a little like the Date: or X-Request-ID headers - we may want to ensure the reponse
251
+
This is a little like the Date: or X-Request-ID headers - we may want to ensure the response
246
252
has a field, but we know that the value for that field changes every time.
247
253
248
254
@@ -253,14 +259,14 @@ Sooner or later the response may have values that could be correct or incorrect
253
259
meaning of data.
254
260
255
261
e.g. does the order of the value matter in this array `[1,2,3]`? Is `[2,1,3]` the same? Almost always
256
-
no, but its more grey with something like `[{"StockId": 221313},{"StockId": 621142}]`. at this point
262
+
no, but it's more grey with something like `[{"StockId": 221313},{"StockId": 621142}]`. At this point
257
263
the answer may end up being "it depends".
258
264
259
265
Sometimes we are working with an ordered list, and sometimes we are not. JSON has no "set" datatype. Some
260
266
JSON HTTP Responses might have multiple arrays, some which need to be treated as ordered arrays, and
261
267
some that should be treated as unordered sets.
262
268
263
-
And another valid JSON reponse might be `{"a":1, "a":2}`, which is "valid" JSON text under RFC 8259, but it’s not "well-defined". Treating this consistantly is also hard.
269
+
And another valid JSON response might be `{"a":1, "a":2}`, which is "valid" JSON text under RFC 8259, but it's not "well-defined". Treating this consistently is also hard.
264
270
265
271
And then there is Unicode normalisation: "é" vs "e\u0301"
266
272
@@ -298,11 +304,11 @@ Actual Response:
298
304
```
299
305
300
306
If we just want to ensure that the status code is working as expected, then we may want to
301
-
only check if the expcted response is a subset of the actual reponse.
307
+
only check if the expected response is a subset of the actual response.
302
308
303
309
## Ignoring values
304
310
305
-
Building on the subset exampkle above, it may be good to do a subset match, but also have the
311
+
Building on the subset example above, it may be good to do a subset match, but also have the
306
312
ability to ignore the values of certain fields, but check that they are present.
0 commit comments