1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "encoding/json"
11 "fmt"
12 "net/http"
13 "testing"
14
15 "github.com/google/go-cmp/cmp"
16 )
17
18 func TestPullRequestsService_ListReviews(t *testing.T) {
19 client, mux, _, teardown := setup()
20 defer teardown()
21
22 mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) {
23 testMethod(t, r, "GET")
24 testFormValues(t, r, values{
25 "page": "2",
26 })
27 fmt.Fprint(w, `[{"id":1},{"id":2}]`)
28 })
29
30 opt := &ListOptions{Page: 2}
31 ctx := context.Background()
32 reviews, _, err := client.PullRequests.ListReviews(ctx, "o", "r", 1, opt)
33 if err != nil {
34 t.Errorf("PullRequests.ListReviews returned error: %v", err)
35 }
36
37 want := []*PullRequestReview{
38 {ID: Int64(1)},
39 {ID: Int64(2)},
40 }
41 if !cmp.Equal(reviews, want) {
42 t.Errorf("PullRequests.ListReviews returned %+v, want %+v", reviews, want)
43 }
44
45 const methodName = "ListReviews"
46 testBadOptions(t, methodName, func() (err error) {
47 _, _, err = client.PullRequests.ListReviews(ctx, "\n", "\n", -1, opt)
48 return err
49 })
50
51 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
52 got, resp, err := client.PullRequests.ListReviews(ctx, "o", "r", 1, opt)
53 if got != nil {
54 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
55 }
56 return resp, err
57 })
58 }
59
60 func TestPullRequestsService_ListReviews_invalidOwner(t *testing.T) {
61 client, _, _, teardown := setup()
62 defer teardown()
63
64 ctx := context.Background()
65 _, _, err := client.PullRequests.ListReviews(ctx, "%", "r", 1, nil)
66 testURLParseError(t, err)
67 }
68
69 func TestPullRequestsService_GetReview(t *testing.T) {
70 client, mux, _, teardown := setup()
71 defer teardown()
72
73 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) {
74 testMethod(t, r, "GET")
75 fmt.Fprint(w, `{"id":1}`)
76 })
77
78 ctx := context.Background()
79 review, _, err := client.PullRequests.GetReview(ctx, "o", "r", 1, 1)
80 if err != nil {
81 t.Errorf("PullRequests.GetReview returned error: %v", err)
82 }
83
84 want := &PullRequestReview{ID: Int64(1)}
85 if !cmp.Equal(review, want) {
86 t.Errorf("PullRequests.GetReview returned %+v, want %+v", review, want)
87 }
88
89 const methodName = "GetReview"
90 testBadOptions(t, methodName, func() (err error) {
91 _, _, err = client.PullRequests.GetReview(ctx, "\n", "\n", -1, -1)
92 return err
93 })
94
95 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
96 got, resp, err := client.PullRequests.GetReview(ctx, "o", "r", 1, 1)
97 if got != nil {
98 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
99 }
100 return resp, err
101 })
102 }
103
104 func TestPullRequestsService_GetReview_invalidOwner(t *testing.T) {
105 client, _, _, teardown := setup()
106 defer teardown()
107
108 ctx := context.Background()
109 _, _, err := client.PullRequests.GetReview(ctx, "%", "r", 1, 1)
110 testURLParseError(t, err)
111 }
112
113 func TestPullRequestsService_DeletePendingReview(t *testing.T) {
114 client, mux, _, teardown := setup()
115 defer teardown()
116
117 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) {
118 testMethod(t, r, "DELETE")
119 fmt.Fprint(w, `{"id":1}`)
120 })
121
122 ctx := context.Background()
123 review, _, err := client.PullRequests.DeletePendingReview(ctx, "o", "r", 1, 1)
124 if err != nil {
125 t.Errorf("PullRequests.DeletePendingReview returned error: %v", err)
126 }
127
128 want := &PullRequestReview{ID: Int64(1)}
129 if !cmp.Equal(review, want) {
130 t.Errorf("PullRequests.DeletePendingReview returned %+v, want %+v", review, want)
131 }
132
133 const methodName = "DeletePendingReview"
134 testBadOptions(t, methodName, func() (err error) {
135 _, _, err = client.PullRequests.DeletePendingReview(ctx, "\n", "\n", -1, -1)
136 return err
137 })
138
139 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
140 got, resp, err := client.PullRequests.DeletePendingReview(ctx, "o", "r", 1, 1)
141 if got != nil {
142 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
143 }
144 return resp, err
145 })
146 }
147
148 func TestPullRequestsService_DeletePendingReview_invalidOwner(t *testing.T) {
149 client, _, _, teardown := setup()
150 defer teardown()
151
152 ctx := context.Background()
153 _, _, err := client.PullRequests.DeletePendingReview(ctx, "%", "r", 1, 1)
154 testURLParseError(t, err)
155 }
156
157 func TestPullRequestsService_ListReviewComments(t *testing.T) {
158 client, mux, _, teardown := setup()
159 defer teardown()
160
161 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) {
162 testMethod(t, r, "GET")
163 fmt.Fprint(w, `[{"id":1},{"id":2}]`)
164 })
165
166 ctx := context.Background()
167 comments, _, err := client.PullRequests.ListReviewComments(ctx, "o", "r", 1, 1, nil)
168 if err != nil {
169 t.Errorf("PullRequests.ListReviewComments returned error: %v", err)
170 }
171
172 want := []*PullRequestComment{
173 {ID: Int64(1)},
174 {ID: Int64(2)},
175 }
176 if !cmp.Equal(comments, want) {
177 t.Errorf("PullRequests.ListReviewComments returned %+v, want %+v", comments, want)
178 }
179
180 const methodName = "ListReviewComments"
181 testBadOptions(t, methodName, func() (err error) {
182 _, _, err = client.PullRequests.ListReviewComments(ctx, "\n", "\n", -1, -1, nil)
183 return err
184 })
185
186 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
187 got, resp, err := client.PullRequests.ListReviewComments(ctx, "o", "r", 1, 1, nil)
188 if got != nil {
189 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
190 }
191 return resp, err
192 })
193 }
194
195 func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) {
196 client, mux, _, teardown := setup()
197 defer teardown()
198
199 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) {
200 testMethod(t, r, "GET")
201 testFormValues(t, r, values{
202 "page": "2",
203 })
204 fmt.Fprint(w, `[]`)
205 })
206
207 ctx := context.Background()
208 _, _, err := client.PullRequests.ListReviewComments(ctx, "o", "r", 1, 1, &ListOptions{Page: 2})
209 if err != nil {
210 t.Errorf("PullRequests.ListReviewComments returned error: %v", err)
211 }
212
213 const methodName = "ListReviewComments"
214 testBadOptions(t, methodName, func() (err error) {
215 _, _, err = client.PullRequests.ListReviewComments(ctx, "\n", "\n", -1, -1, &ListOptions{Page: 2})
216 return err
217 })
218
219 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
220 got, resp, err := client.PullRequests.ListReviewComments(ctx, "o", "r", 1, 1, &ListOptions{Page: 2})
221 if got != nil {
222 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
223 }
224 return resp, err
225 })
226 }
227
228 func TestPullRequestReviewRequest_isComfortFadePreview(t *testing.T) {
229 path := "path/to/file.go"
230 body := "this is a comment body"
231 left, right := "LEFT", "RIGHT"
232 pos1, pos2, pos3 := 1, 2, 3
233 line1, line2, line3 := 11, 22, 33
234
235 tests := []struct {
236 name string
237 review *PullRequestReviewRequest
238 wantErr error
239 wantBool bool
240 }{{
241 name: "empty review",
242 review: &PullRequestReviewRequest{},
243 wantBool: false,
244 }, {
245 name: "nil comment",
246 review: &PullRequestReviewRequest{Comments: []*DraftReviewComment{nil}},
247 wantBool: false,
248 }, {
249 name: "old-style review",
250 review: &PullRequestReviewRequest{
251 Comments: []*DraftReviewComment{{
252 Path: &path,
253 Body: &body,
254 Position: &pos1,
255 }, {
256 Path: &path,
257 Body: &body,
258 Position: &pos2,
259 }, {
260 Path: &path,
261 Body: &body,
262 Position: &pos3,
263 }},
264 },
265 wantBool: false,
266 }, {
267 name: "new-style review",
268 review: &PullRequestReviewRequest{
269 Comments: []*DraftReviewComment{{
270 Path: &path,
271 Body: &body,
272 Side: &right,
273 Line: &line1,
274 }, {
275 Path: &path,
276 Body: &body,
277 Side: &left,
278 Line: &line2,
279 }, {
280 Path: &path,
281 Body: &body,
282 Side: &right,
283 Line: &line3,
284 }},
285 },
286 wantBool: true,
287 }, {
288 name: "blended comment",
289 review: &PullRequestReviewRequest{
290 Comments: []*DraftReviewComment{{
291 Path: &path,
292 Body: &body,
293 Position: &pos1,
294 Side: &right,
295 Line: &line1,
296 }},
297 },
298 wantErr: ErrMixedCommentStyles,
299 }, {
300 name: "position then line",
301 review: &PullRequestReviewRequest{
302 Comments: []*DraftReviewComment{{
303 Path: &path,
304 Body: &body,
305 Position: &pos1,
306 }, {
307 Path: &path,
308 Body: &body,
309 Side: &right,
310 Line: &line1,
311 }},
312 },
313 wantErr: ErrMixedCommentStyles,
314 }, {
315 name: "line then position",
316 review: &PullRequestReviewRequest{
317 Comments: []*DraftReviewComment{{
318 Path: &path,
319 Body: &body,
320 Side: &right,
321 Line: &line1,
322 }, {
323 Path: &path,
324 Body: &body,
325 Position: &pos1,
326 }},
327 },
328 wantErr: ErrMixedCommentStyles,
329 }}
330
331 for _, tc := range tests {
332 t.Run(tc.name, func(t *testing.T) {
333 gotBool, gotErr := tc.review.isComfortFadePreview()
334 if tc.wantErr != nil {
335 if gotErr != tc.wantErr {
336 t.Errorf("isComfortFadePreview() = %v, wanted %v", gotErr, tc.wantErr)
337 }
338 } else {
339 if gotBool != tc.wantBool {
340 t.Errorf("isComfortFadePreview() = %v, wanted %v", gotBool, tc.wantBool)
341 }
342 }
343 })
344 }
345 }
346
347 func TestPullRequestsService_ListReviewComments_invalidOwner(t *testing.T) {
348 client, _, _, teardown := setup()
349 defer teardown()
350
351 ctx := context.Background()
352 _, _, err := client.PullRequests.ListReviewComments(ctx, "%", "r", 1, 1, nil)
353 testURLParseError(t, err)
354 }
355
356 func TestPullRequestsService_CreateReview(t *testing.T) {
357 client, mux, _, teardown := setup()
358 defer teardown()
359
360 input := &PullRequestReviewRequest{
361 CommitID: String("commit_id"),
362 Body: String("b"),
363 Event: String("APPROVE"),
364 }
365
366 mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) {
367 v := new(PullRequestReviewRequest)
368 json.NewDecoder(r.Body).Decode(v)
369
370 testMethod(t, r, "POST")
371 if !cmp.Equal(v, input) {
372 t.Errorf("Request body = %+v, want %+v", v, input)
373 }
374
375 fmt.Fprint(w, `{"id":1}`)
376 })
377
378 ctx := context.Background()
379 review, _, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, input)
380 if err != nil {
381 t.Errorf("PullRequests.CreateReview returned error: %v", err)
382 }
383
384 want := &PullRequestReview{ID: Int64(1)}
385 if !cmp.Equal(review, want) {
386 t.Errorf("PullRequests.CreateReview returned %+v, want %+v", review, want)
387 }
388
389 const methodName = "CreateReview"
390 testBadOptions(t, methodName, func() (err error) {
391 _, _, err = client.PullRequests.CreateReview(ctx, "\n", "\n", -1, input)
392 return err
393 })
394
395 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
396 got, resp, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, input)
397 if got != nil {
398 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
399 }
400 return resp, err
401 })
402 }
403
404 func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) {
405 client, _, _, teardown := setup()
406 defer teardown()
407
408 ctx := context.Background()
409 _, _, err := client.PullRequests.CreateReview(ctx, "%", "r", 1, &PullRequestReviewRequest{})
410 testURLParseError(t, err)
411 }
412
413 func TestPullRequestsService_CreateReview_badReview(t *testing.T) {
414 client, _, _, teardown := setup()
415 defer teardown()
416
417 ctx := context.Background()
418
419 path := "path/to/file.go"
420 body := "this is a comment body"
421 right := "RIGHT"
422 pos1 := 1
423 line1 := 11
424 badReview := &PullRequestReviewRequest{
425 Comments: []*DraftReviewComment{{
426 Path: &path,
427 Body: &body,
428 Side: &right,
429 Line: &line1,
430 }, {
431 Path: &path,
432 Body: &body,
433 Position: &pos1,
434 }}}
435
436 _, _, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, badReview)
437 if err == nil {
438 t.Errorf("CreateReview badReview err = nil, want err")
439 }
440 }
441
442 func TestPullRequestsService_CreateReview_addHeader(t *testing.T) {
443 client, mux, _, teardown := setup()
444 defer teardown()
445
446 path := "path/to/file.go"
447 body := "this is a comment body"
448 left, right := "LEFT", "RIGHT"
449 line1, line2, line3 := 11, 22, 33
450 input := &PullRequestReviewRequest{
451 Comments: []*DraftReviewComment{{
452 Path: &path,
453 Body: &body,
454 Side: &right,
455 Line: &line1,
456 }, {
457 Path: &path,
458 Body: &body,
459 Side: &left,
460 Line: &line2,
461 }, {
462 Path: &path,
463 Body: &body,
464 Side: &right,
465 Line: &line3,
466 }},
467 }
468
469 mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) {
470 v := new(PullRequestReviewRequest)
471 json.NewDecoder(r.Body).Decode(v)
472
473 testMethod(t, r, "POST")
474 if !cmp.Equal(v, input) {
475 t.Errorf("Request body = %+v, want %+v", v, input)
476 }
477
478 fmt.Fprint(w, `{"id":1}`)
479 })
480
481 ctx := context.Background()
482
483 _, _, err := client.PullRequests.CreateReview(ctx, "o", "r", 1, input)
484 if err != nil {
485 t.Errorf("CreateReview addHeader err = %v, want nil", err)
486 }
487 }
488
489 func TestPullRequestsService_UpdateReview(t *testing.T) {
490 client, mux, _, teardown := setup()
491 defer teardown()
492
493 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) {
494 testMethod(t, r, "PUT")
495 fmt.Fprintf(w, `{"id":1}`)
496 })
497
498 ctx := context.Background()
499 got, _, err := client.PullRequests.UpdateReview(ctx, "o", "r", 1, 1, "updated_body")
500 if err != nil {
501 t.Errorf("PullRequests.UpdateReview returned error: %v", err)
502 }
503
504 want := &PullRequestReview{ID: Int64(1)}
505 if !cmp.Equal(got, want) {
506 t.Errorf("PullRequests.UpdateReview = %+v, want %+v", got, want)
507 }
508
509 const methodName = "UpdateReview"
510 testBadOptions(t, methodName, func() (err error) {
511 _, _, err = client.PullRequests.UpdateReview(ctx, "\n", "\n", -1, -1, "updated_body")
512 return err
513 })
514
515 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
516 got, resp, err := client.PullRequests.UpdateReview(ctx, "o", "r", 1, 1, "updated_body")
517 if got != nil {
518 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
519 }
520 return resp, err
521 })
522 }
523
524 func TestPullRequestsService_SubmitReview(t *testing.T) {
525 client, mux, _, teardown := setup()
526 defer teardown()
527
528 input := &PullRequestReviewRequest{
529 Body: String("b"),
530 Event: String("APPROVE"),
531 }
532
533 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/events", func(w http.ResponseWriter, r *http.Request) {
534 v := new(PullRequestReviewRequest)
535 json.NewDecoder(r.Body).Decode(v)
536
537 testMethod(t, r, "POST")
538 if !cmp.Equal(v, input) {
539 t.Errorf("Request body = %+v, want %+v", v, input)
540 }
541
542 fmt.Fprint(w, `{"id":1}`)
543 })
544
545 ctx := context.Background()
546 review, _, err := client.PullRequests.SubmitReview(ctx, "o", "r", 1, 1, input)
547 if err != nil {
548 t.Errorf("PullRequests.SubmitReview returned error: %v", err)
549 }
550
551 want := &PullRequestReview{ID: Int64(1)}
552 if !cmp.Equal(review, want) {
553 t.Errorf("PullRequests.SubmitReview returned %+v, want %+v", review, want)
554 }
555
556 const methodName = "SubmitReview"
557 testBadOptions(t, methodName, func() (err error) {
558 _, _, err = client.PullRequests.SubmitReview(ctx, "\n", "\n", -1, -1, input)
559 return err
560 })
561
562 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
563 got, resp, err := client.PullRequests.SubmitReview(ctx, "o", "r", 1, 1, input)
564 if got != nil {
565 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
566 }
567 return resp, err
568 })
569 }
570
571 func TestPullRequestsService_SubmitReview_invalidOwner(t *testing.T) {
572 client, _, _, teardown := setup()
573 defer teardown()
574
575 ctx := context.Background()
576 _, _, err := client.PullRequests.SubmitReview(ctx, "%", "r", 1, 1, &PullRequestReviewRequest{})
577 testURLParseError(t, err)
578 }
579
580 func TestPullRequestsService_DismissReview(t *testing.T) {
581 client, mux, _, teardown := setup()
582 defer teardown()
583
584 input := &PullRequestReviewDismissalRequest{Message: String("m")}
585
586 mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/dismissals", func(w http.ResponseWriter, r *http.Request) {
587 v := new(PullRequestReviewDismissalRequest)
588 json.NewDecoder(r.Body).Decode(v)
589
590 testMethod(t, r, "PUT")
591 if !cmp.Equal(v, input) {
592 t.Errorf("Request body = %+v, want %+v", v, input)
593 }
594
595 fmt.Fprint(w, `{"id":1}`)
596 })
597
598 ctx := context.Background()
599 review, _, err := client.PullRequests.DismissReview(ctx, "o", "r", 1, 1, input)
600 if err != nil {
601 t.Errorf("PullRequests.DismissReview returned error: %v", err)
602 }
603
604 want := &PullRequestReview{ID: Int64(1)}
605 if !cmp.Equal(review, want) {
606 t.Errorf("PullRequests.DismissReview returned %+v, want %+v", review, want)
607 }
608
609 const methodName = "ListReviews"
610 testBadOptions(t, methodName, func() (err error) {
611 _, _, err = client.PullRequests.DismissReview(ctx, "\n", "\n", -1, -1, input)
612 return err
613 })
614
615 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
616 got, resp, err := client.PullRequests.DismissReview(ctx, "o", "r", 1, 1, input)
617 if got != nil {
618 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
619 }
620 return resp, err
621 })
622 }
623
624 func TestPullRequestsService_DismissReview_invalidOwner(t *testing.T) {
625 client, _, _, teardown := setup()
626 defer teardown()
627
628 ctx := context.Background()
629 _, _, err := client.PullRequests.DismissReview(ctx, "%", "r", 1, 1, &PullRequestReviewDismissalRequest{})
630 testURLParseError(t, err)
631 }
632
633 func TestPullRequestReviewDismissalRequest_Marshal(t *testing.T) {
634 testJSONMarshal(t, &PullRequestReviewDismissalRequest{}, "{}")
635
636 u := &PullRequestReviewDismissalRequest{
637 Message: String("msg"),
638 }
639
640 want := `{
641 "message": "msg"
642 }`
643
644 testJSONMarshal(t, u, want)
645 }
646
647 func TestDraftReviewComment_Marshal(t *testing.T) {
648 testJSONMarshal(t, &DraftReviewComment{}, "{}")
649
650 u := &DraftReviewComment{
651 Path: String("path"),
652 Position: Int(1),
653 Body: String("body"),
654 StartSide: String("ss"),
655 Side: String("side"),
656 StartLine: Int(1),
657 Line: Int(1),
658 }
659
660 want := `{
661 "path": "path",
662 "position": 1,
663 "body": "body",
664 "start_side": "ss",
665 "side": "side",
666 "start_line": 1,
667 "line": 1
668 }`
669
670 testJSONMarshal(t, u, want)
671 }
672
673 func TestPullRequestReviewRequest_Marshal(t *testing.T) {
674 testJSONMarshal(t, &PullRequestReviewRequest{}, "{}")
675
676 u := &PullRequestReviewRequest{
677 NodeID: String("nodeid"),
678 CommitID: String("cid"),
679 Body: String("body"),
680 Event: String("event"),
681 Comments: []*DraftReviewComment{
682 {
683 Path: String("path"),
684 Position: Int(1),
685 Body: String("body"),
686 StartSide: String("ss"),
687 Side: String("side"),
688 StartLine: Int(1),
689 Line: Int(1),
690 },
691 },
692 }
693
694 want := `{
695 "node_id": "nodeid",
696 "commit_id": "cid",
697 "body": "body",
698 "event": "event",
699 "comments": [
700 {
701 "path": "path",
702 "position": 1,
703 "body": "body",
704 "start_side": "ss",
705 "side": "side",
706 "start_line": 1,
707 "line": 1
708 }
709 ]
710 }`
711
712 testJSONMarshal(t, u, want)
713 }
714
715 func TestPullRequestReview_Marshal(t *testing.T) {
716 testJSONMarshal(t, &PullRequestReview{}, "{}")
717
718 u := &PullRequestReview{
719 ID: Int64(1),
720 NodeID: String("nid"),
721 User: &User{
722 Login: String("l"),
723 ID: Int64(1),
724 URL: String("u"),
725 AvatarURL: String("a"),
726 GravatarID: String("g"),
727 Name: String("n"),
728 Company: String("c"),
729 Blog: String("b"),
730 Location: String("l"),
731 Email: String("e"),
732 Hireable: Bool(true),
733 Bio: String("b"),
734 TwitterUsername: String("t"),
735 PublicRepos: Int(1),
736 Followers: Int(1),
737 Following: Int(1),
738 CreatedAt: &Timestamp{referenceTime},
739 SuspendedAt: &Timestamp{referenceTime},
740 },
741 Body: String("body"),
742 SubmittedAt: &Timestamp{referenceTime},
743 CommitID: String("cid"),
744 HTMLURL: String("hurl"),
745 PullRequestURL: String("prurl"),
746 State: String("state"),
747 AuthorAssociation: String("aa"),
748 }
749
750 want := `{
751 "id": 1,
752 "node_id": "nid",
753 "user": {
754 "login": "l",
755 "id": 1,
756 "avatar_url": "a",
757 "gravatar_id": "g",
758 "name": "n",
759 "company": "c",
760 "blog": "b",
761 "location": "l",
762 "email": "e",
763 "hireable": true,
764 "bio": "b",
765 "twitter_username": "t",
766 "public_repos": 1,
767 "followers": 1,
768 "following": 1,
769 "created_at": ` + referenceTimeStr + `,
770 "suspended_at": ` + referenceTimeStr + `,
771 "url": "u"
772 },
773 "body": "body",
774 "submitted_at": ` + referenceTimeStr + `,
775 "commit_id": "cid",
776 "html_url": "hurl",
777 "pull_request_url": "prurl",
778 "state": "state",
779 "author_association": "aa"
780 }`
781
782 testJSONMarshal(t, u, want)
783 }
784
View as plain text