Repository navigation
Expand file tree
/
Copy pathinstance_problem_test.go
More file actions
515 lines (475 loc) · 21 KB
/
Copy pathinstance_problem_test.go
File metadata and controls
515 lines (475 loc) · 21 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
package api
import (
"encoding/json"
"math"
"net/http"
"reflect"
"strings"
"sync"
"testing"
"github.com/jgolang/errors"
"github.com/jgolang/errors/codes"
)
var taskNotFound = codes.New("PLN-404", "task not found").WithKind(codes.KindNotFound)
func writeTaskNotFound(w http.ResponseWriter, r *http.Request) {
WriteError(w, r, errors.NewC(taskNotFound, "task 7"))
}
func problemInstance(opts ...Option) *API {
return New(append([]Option{WithResponseMode(ResponseModeProblem)}, opts...)...)
}
// decodeMembers decodes a JSON object body into its members.
func decodeMembers(t *testing.T, body []byte) map[string]any {
t.Helper()
var members map[string]any
if err := json.Unmarshal(body, &members); err != nil {
t.Fatalf("decoding %s: %v", body, err)
}
return members
}
func TestProblemInstanceWritesAnErrorAsProblemDetails(t *testing.T) {
a := problemInstance()
rec := serve(a.Handler(http.HandlerFunc(writeTaskNotFound)), http.MethodGet, "", map[string]string{EventIDHeaderKey: "evt-123"})
if rec.Code != http.StatusNotFound {
t.Fatalf("status = %d, want 404", rec.Code)
}
if got := rec.Header().Get("Content-Type"); got != problemContentType {
t.Fatalf("Content-Type = %q, want %q", got, problemContentType)
}
want := `{"type":"about:blank","title":"Not Found","status":404,"detail":"task not found","code":"PLN-404","event_id":"evt-123"}`
if got := strings.TrimSpace(rec.Body.String()); got != want {
t.Fatalf("body = %s, want %s", got, want)
}
}
func TestProblemDetailsMembers(t *testing.T) {
tests := []struct {
name string
a *API
handler http.HandlerFunc
body string
headers map[string]string
// ignoreEventID drops event_id before comparing: only ProcessRequest
// generates one for a request without an event ID header.
ignoreEventID bool
want map[string]any
}{
{
name: "no event ID",
a: problemInstance(),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Not Found", "status": 404.0, "detail": "task not found", "code": "PLN-404"},
},
{
name: "lowercase codes",
a: problemInstance(WithLowercaseCodes()),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Not Found", "status": 404.0, "detail": "task not found", "code": "pln-404"},
},
{
name: "Error400",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { Error400().Write(w, r) },
want: map[string]any{"type": "about:blank", "title": "Bad Request", "status": 400.0, "detail": DefaultErrorMessage, "code": "E001"},
},
{
name: "Error401",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { Error401().Write(w, r) },
want: map[string]any{"type": "about:blank", "title": "Unauthorized", "status": 401.0, "detail": UnauthorizedMessage, "code": "B001"},
},
{
name: "WriteError nil",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { WriteError(w, r, nil) },
want: map[string]any{"type": "about:blank", "title": "Internal Server Error", "status": 500.0, "detail": InternalServerMessage, "code": "E300"},
},
{
name: "formatter value",
a: problemInstance(WithResponseFormatter(ResponseFormatter{})),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Not Found", "status": 404.0, "detail": "task not found", "code": "PLN-404"},
},
{
name: "formatter pointer",
a: problemInstance(WithResponseFormatter(&ResponseFormatter{})),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Not Found", "status": 404.0, "detail": "task not found", "code": "PLN-404"},
},
{
// The rejection comes before ProcessRequest generates an event ID.
name: "ProcessRequest bad JSON",
a: problemInstance(),
handler: ProcessRequest(writeSuccess),
body: `{"title":`,
want: map[string]any{"type": "about:blank", "title": "Bad Request", "status": 400.0, "detail": "Request content empty json structure", "code": "E002"},
},
{
name: "ProcessRequest panic",
a: problemInstance(),
handler: ProcessRequest(func(http.ResponseWriter, *http.Request) { panic("boom") }),
ignoreEventID: true,
want: map[string]any{"type": "about:blank", "title": "Internal Server Error", "status": 500.0, "detail": InternalServerMessage, "code": "E300"},
},
{
name: "WithKindStatus 410",
a: problemInstance(WithKindStatus(codes.KindNotFound, http.StatusGone)),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Gone", "status": 410.0, "detail": "task not found", "code": "PLN-404"},
},
{
name: "WithKindStatus 503",
a: problemInstance(WithKindStatus(codes.KindNotFound, http.StatusServiceUnavailable)),
handler: writeTaskNotFound,
want: map[string]any{"type": "about:blank", "title": "Service Unavailable", "status": 503.0, "detail": "task not found", "code": "PLN-404"},
},
{
name: "BasicToken",
a: problemInstance(),
handler: BasicToken(writeSuccess),
want: map[string]any{"type": "about:blank", "title": "Unauthorized", "status": 401.0, "detail": DefaultInvalidAuthHeaderMsg, "code": "B001"},
},
{
name: "CustomToken",
a: problemInstance(),
handler: CustomToken(writeSuccess),
want: map[string]any{"type": "about:blank", "title": "Unauthorized", "status": 401.0, "detail": DefaultInvalidAuthHeaderMsg, "code": "B001"},
},
{
name: "RequestHeaderJSON",
a: problemInstance(),
handler: RequestHeaderJSON(writeSuccess),
body: `{}`,
headers: map[string]string{"Content-Type": "text/plain"},
want: map[string]any{"type": "about:blank", "title": "Unsupported Media Type", "status": 415.0, "detail": "Content-Type not is JSON!", "code": "E002"},
},
{
name: "RequestHeaderSession",
a: problemInstance(),
handler: RequestHeaderSession(writeSuccess),
want: map[string]any{"type": "about:blank", "title": "Unauthorized", "status": 401.0, "detail": "Invalid session ID", "code": "B001"},
},
{
name: "RequestBody",
a: problemInstance(),
handler: RequestBody(writeSuccess),
body: `{"title":`,
want: map[string]any{"type": "about:blank", "title": "Bad Request", "status": 400.0, "detail": "Request content empty json structure", "code": "E002"},
},
{
name: "Error403",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { Error403().Write(w, r) },
want: map[string]any{"type": "about:blank", "title": "Forbidden", "status": 403.0, "detail": UnauthorizedMessage, "code": "B002"},
},
{
name: "Error500",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { Error500().Write(w, r) },
want: map[string]any{"type": "about:blank", "title": "Internal Server Error", "status": 500.0, "detail": InternalServerMessage, "code": "E300"},
},
{
name: "Error501",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) { Error501().Write(w, r) },
want: map[string]any{"type": "about:blank", "title": "Not Implemented", "status": 501.0, "detail": InternalServerMessage, "code": "E001"},
},
{
// Token, content, actions and info never reach a problem body.
name: "token, content and info left out",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) {
response := Error400()
response.Content = map[string]string{"field": "title"}
response.SecurityToken = "s3cr3t"
response.Actions = "retry"
response.Info = map[string]string{"k": "v"}
response.Write(w, r)
},
headers: map[string]string{"Authorization": "Bearer t0k3n"},
want: map[string]any{"type": "about:blank", "title": "Bad Request", "status": 400.0, "detail": DefaultErrorMessage, "code": "E001"},
},
{
name: "empty Content-Type in Headers",
a: problemInstance(),
handler: func(w http.ResponseWriter, r *http.Request) {
Error{Headers: map[string]string{"Content-Type": ""}}.Write(w, r)
},
want: map[string]any{"type": "about:blank", "title": "Bad Request", "status": 400.0, "detail": DefaultErrorMessage, "code": "E001"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := serve(tt.a.Handler(tt.handler), http.MethodPost, tt.body, tt.headers)
if got := rec.Header().Get("Content-Type"); got != problemContentType {
t.Fatalf("Content-Type = %q, want %q", got, problemContentType)
}
if want := int(tt.want["status"].(float64)); rec.Code != want {
t.Fatalf("status = %d, want %d", rec.Code, want)
}
got := decodeMembers(t, rec.Body.Bytes())
if tt.ignoreEventID {
delete(got, "event_id")
}
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("members = %v, want %v", got, tt.want)
}
})
}
}
func TestProblemInstanceWritesOtherResponsesAsContent(t *testing.T) {
content := map[string]int{"id": 1}
tests := []struct {
name string
handler http.HandlerFunc
}{
{"Success", func(w http.ResponseWriter, r *http.Request) { SuccessWithContent(content).Write(w, r) }},
{"Warning", func(w http.ResponseWriter, r *http.Request) {
Warning{HTTPStatusCode: http.StatusOK, Content: content}.Write(w, r)
}},
{"Informative", func(w http.ResponseWriter, r *http.Request) {
Informative{HTTPStatusCode: http.StatusOK, Content: content}.Write(w, r)
}},
// A Content-Type the handler put on w.Header() never labels the body.
{"handler preset text/html", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
SuccessWithContent(content).Write(w, r)
}},
{"empty Content-Type in Headers", func(w http.ResponseWriter, r *http.Request) {
Success{Content: content, Headers: map[string]string{"Content-Type": ""}}.Write(w, r)
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := serve(problemInstance().Handler(tt.handler), http.MethodGet, "", nil)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200", rec.Code)
}
if got := rec.Header().Get("Content-Type"); got != "application/json" {
t.Fatalf("Content-Type = %q, want application/json", got)
}
if got := strings.TrimSpace(rec.Body.String()); got != `{"id":1}` {
t.Fatalf("body = %s, want the content alone", got)
}
})
}
}
func TestProblemInstanceKeepsHeadersWithoutChangingTheCallersMap(t *testing.T) {
headers := map[string]string{"X-Trace": "t"}
handler := func(w http.ResponseWriter, r *http.Request) {
Error{Headers: headers}.Write(w, r)
}
rec := serve(problemInstance().Handler(http.HandlerFunc(handler)), http.MethodGet, "", nil)
if got := rec.Header().Get("X-Trace"); got != "t" {
t.Fatalf("X-Trace = %q, want t", got)
}
if got := rec.Header().Get("Content-Type"); got != problemContentType {
t.Fatalf("Content-Type = %q, want %q", got, problemContentType)
}
if want := map[string]string{"X-Trace": "t"}; !reflect.DeepEqual(headers, want) {
t.Fatalf("caller's headers = %v, want %v", headers, want)
}
}
func TestProblemInstanceKeepsTheCallersContentType(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
Error{Headers: map[string]string{"content-type": "application/vnd.x+json"}}.Write(w, r)
}
rec := serve(problemInstance().Handler(http.HandlerFunc(handler)), http.MethodGet, "", nil)
if got := rec.Header().Get("Content-Type"); got != "application/vnd.x+json" {
t.Fatalf("Content-Type = %q, want the caller's", got)
}
}
func TestBuiltInWriterKeepsAContentTypeSetInHeaders(t *testing.T) {
csv := func(w http.ResponseWriter, r *http.Request) {
Success{Headers: map[string]string{"Content-Type": "text/csv"}}.Write(w, r)
}
plain := func(w http.ResponseWriter, r *http.Request) { Success200().Write(w, r) }
empty := func(w http.ResponseWriter, r *http.Request) {
Success{Headers: map[string]string{"content-type": ""}}.Write(w, r)
}
preset := func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
Success200().Write(w, r)
}
plainInstance := New(WithResponseMode(ResponseModePlain))
tests := []struct {
name string
handler http.Handler
want string
}{
{"default instance with Content-Type", http.HandlerFunc(csv), "text/csv"},
{"default instance without Content-Type", http.HandlerFunc(plain), "application/json"},
{"plain instance with Content-Type", plainInstance.Handler(http.HandlerFunc(csv)), "text/csv"},
{"plain instance without Content-Type", plainInstance.Handler(http.HandlerFunc(plain)), "application/json"},
{"default instance with empty Content-Type", http.HandlerFunc(empty), "application/json"},
{"plain instance with empty Content-Type", plainInstance.Handler(http.HandlerFunc(empty)), "application/json"},
{"default instance with handler preset text/html", http.HandlerFunc(preset), "application/json"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := serve(tt.handler, http.MethodGet, "", nil)
if got := rec.Header().Get("Content-Type"); got != tt.want {
t.Fatalf("Content-Type = %q, want %q", got, tt.want)
}
})
}
}
func TestProblemInstanceAnswersProblem500WhenResponseCannotBeEncoded(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
SuccessWithContent(math.NaN()).Write(w, r)
}
rec := serve(problemInstance().Handler(http.HandlerFunc(handler)), http.MethodGet, "", nil)
if rec.Code != http.StatusInternalServerError {
t.Fatalf("status = %d, want 500", rec.Code)
}
if got := rec.Header().Get("Content-Type"); got != problemContentType {
t.Fatalf("Content-Type = %q, want %q", got, problemContentType)
}
want := map[string]any{"type": "about:blank", "title": "Internal Server Error", "status": 500.0, "detail": InternalServerMessage, "code": "E300"}
if got := decodeMembers(t, rec.Body.Bytes()); !reflect.DeepEqual(got, want) {
t.Fatalf("members = %v, want %v", got, want)
}
}
func TestProblemEnvelopeAndDefaultInstancesServeConcurrently(t *testing.T) {
problem := problemInstance().Handler(http.HandlerFunc(writeTaskNotFound))
envelope := New().Handler(http.HandlerFunc(writeTaskNotFound))
unwrapped := http.HandlerFunc(writeTaskNotFound)
var wg sync.WaitGroup
for range 20 {
wg.Go(func() {
rec := serve(problem, http.MethodGet, "", nil)
if got := rec.Header().Get("Content-Type"); got != problemContentType {
t.Errorf("problem Content-Type = %q", got)
}
})
wg.Go(func() {
rec := serve(envelope, http.MethodGet, "", nil)
if got := responseModeOf(rec.Body.Bytes()); got != ResponseModeEnvelope {
t.Errorf("instance response mode = %s, want envelope", got)
}
})
wg.Go(func() {
rec := serve(unwrapped, http.MethodGet, "", nil)
if got := responseModeOf(rec.Body.Bytes()); got != ResponseModeEnvelope {
t.Errorf("default response mode = %s, want envelope", got)
}
})
}
wg.Wait()
}
func TestEncodeFailureSendsTheFormattersContentType(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
Success{Content: math.NaN(), Headers: map[string]string{"content-type": "text/csv", "X-Trace": "t"}}.Write(w, r)
}
tests := []struct {
name string
a *API
want string
}{
{"envelope instance", New(), "application/json"},
{"problem instance", problemInstance(), problemContentType},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := serve(tt.a.Handler(http.HandlerFunc(handler)), http.MethodGet, "", nil)
if rec.Code != http.StatusInternalServerError {
t.Fatalf("status = %d, want 500", rec.Code)
}
if got := rec.Header().Get("Content-Type"); got != tt.want {
t.Fatalf("Content-Type = %q, want %q", got, tt.want)
}
if got := rec.Header().Get("X-Trace"); got != "t" {
t.Fatalf("X-Trace = %q, want t", got)
}
})
}
}
// TestProblemTitleIsTheStatusTextUnlessTheServiceSetIt checks owner answer
// Q39: a problem title is http.StatusText(status) when the response title is
// one the library sets on its own (RFC 9457 section 4.2.1 for about:blank),
// and the title a service set otherwise.
func TestProblemTitleIsTheStatusTextUnlessTheServiceSetIt(t *testing.T) {
tests := []struct {
name string
handler http.HandlerFunc
body string
want string
}{
{name: "WriteError default title", handler: writeTaskNotFound, want: "Not Found"},
{name: "Error400 default title", handler: func(w http.ResponseWriter, r *http.Request) { Error400().Write(w, r) }, want: "Bad Request"},
{name: "empty title", handler: func(w http.ResponseWriter, r *http.Request) { Error{}.Write(w, r) }, want: "Bad Request"},
{name: "unauthorized title", handler: func(w http.ResponseWriter, r *http.Request) { Error403().Write(w, r) }, want: "Forbidden"},
{name: "internal server title", handler: func(w http.ResponseWriter, r *http.Request) { Error501().Write(w, r) }, want: "Not Implemented"},
{name: "rejected body title", handler: ProcessRequest(writeSuccess), body: `{"title":`, want: "Bad Request"},
{name: "query param helper title", handler: func(w http.ResponseWriter, r *http.Request) {
_, response := GetQueryParamValueInt("page", r)
response.Write(w, r)
}, want: "Bad Request"},
{name: "service title", handler: func(w http.ResponseWriter, r *http.Request) {
Error{Title: "Task not found", HTTPStatusCode: http.StatusNotFound}.Write(w, r)
}, want: "Task not found"},
{name: "unknown status keeps the default title", handler: func(w http.ResponseWriter, r *http.Request) {
Error{HTTPStatusCode: 499}.Write(w, r)
}, want: DefaultErrorTitle},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rec := serve(problemInstance().Handler(tt.handler), http.MethodPost, tt.body, nil)
if got := decodeMembers(t, rec.Body.Bytes())["title"]; got != tt.want {
t.Fatalf("title = %v, want %q", got, tt.want)
}
})
}
}
// TestProblemTitleOfEveryResponseHelper checks that the title of each
// Response-returning helper is known as a library title.
func TestProblemTitleOfEveryResponseHelper(t *testing.T) {
helpers := map[string]func(r *http.Request) Response{
"GetHeaderValueString": func(r *http.Request) Response { _, res := GetHeaderValueString("X-Missing", r); return res },
"GetHeaderValueInt": func(r *http.Request) Response { _, res := GetHeaderValueInt("X-Missing", r); return res },
"GetHeaderValueInt64": func(r *http.Request) Response { _, res := GetHeaderValueInt64("X-Missing", r); return res },
"GetHeaderValueFloat64": func(r *http.Request) Response { _, res := GetHeaderValueFloat64("X-Missing", r); return res },
"GetHeaderValueBool": func(r *http.Request) Response { _, res := GetHeaderValueBool("X-Missing", r); return res },
"GetRouteVarValueString": func(r *http.Request) Response { _, res := GetRouteVarValueString("id", r); return res },
"GetRouteVarValueInt": func(r *http.Request) Response { _, res := GetRouteVarValueInt("id", r); return res },
"GetRouteVarValueInt64": func(r *http.Request) Response { _, res := GetRouteVarValueInt64("id", r); return res },
"GetRouteVarValueFloat64": func(r *http.Request) Response { _, res := GetRouteVarValueFloat64("id", r); return res },
"GetRouteVarValueBool": func(r *http.Request) Response { _, res := GetRouteVarValueBool("id", r); return res },
"GetQueryParamValueString": func(r *http.Request) Response {
_, res := GetQueryParamValueString("page", r)
return res
},
"GetQueryParamValueInt": func(r *http.Request) Response { _, res := GetQueryParamValueInt("page", r); return res },
"GetQueryParamValueInt64": func(r *http.Request) Response { _, res := GetQueryParamValueInt64("page", r); return res },
"GetQueryParamValueFloat64": func(r *http.Request) Response { _, res := GetQueryParamValueFloat64("page", r); return res },
"GetQueryParamValueBool": func(r *http.Request) Response { _, res := GetQueryParamValueBool("page", r); return res },
"UnmarshalBody": func(r *http.Request) Response { var v struct{}; return UnmarshalBody(&v, r) },
}
for name, helper := range helpers {
t.Run(name, func(t *testing.T) {
var response Response
handler := func(w http.ResponseWriter, r *http.Request) {
response = helper(r)
if response != nil {
response.Write(w, r)
}
}
rec := serve(problemInstance().Handler(http.HandlerFunc(handler)), http.MethodPost, `{"title":`, nil)
if response == nil {
t.Fatal("helper returned no error response")
}
if got, want := decodeMembers(t, rec.Body.Bytes())["title"], http.StatusText(rec.Code); got != want {
t.Fatalf("title = %v, want %q", got, want)
}
})
}
}
// TestProblemTitleKeepsAReassignedDefaultTitle checks that a default title
// the service reassigned through the package variable counts as its own.
func TestProblemTitleKeepsAReassignedDefaultTitle(t *testing.T) {
previous := DefaultErrorTitle
DefaultErrorTitle = "Task error"
t.Cleanup(func() { DefaultErrorTitle = previous })
rec := serve(problemInstance().Handler(http.HandlerFunc(writeTaskNotFound)), http.MethodGet, "", nil)
if got := decodeMembers(t, rec.Body.Bytes())["title"]; got != "Task error" {
t.Fatalf("title = %v, want the reassigned title", got)
}
}