...

Source file src/github.com/google/go-github/v45/github/pulls_test.go

Documentation: github.com/google/go-github/v45/github

     1  // Copyright 2013 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"encoding/json"
    11  	"fmt"
    12  	"io"
    13  	"net/http"
    14  	"strings"
    15  	"testing"
    16  
    17  	"github.com/google/go-cmp/cmp"
    18  )
    19  
    20  func TestPullRequestsService_List(t *testing.T) {
    21  	client, mux, _, teardown := setup()
    22  	defer teardown()
    23  
    24  	mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) {
    25  		testMethod(t, r, "GET")
    26  		testFormValues(t, r, values{
    27  			"state":     "closed",
    28  			"head":      "h",
    29  			"base":      "b",
    30  			"sort":      "created",
    31  			"direction": "desc",
    32  			"page":      "2",
    33  		})
    34  		fmt.Fprint(w, `[{"number":1}]`)
    35  	})
    36  
    37  	opts := &PullRequestListOptions{"closed", "h", "b", "created", "desc", ListOptions{Page: 2}}
    38  	ctx := context.Background()
    39  	pulls, _, err := client.PullRequests.List(ctx, "o", "r", opts)
    40  	if err != nil {
    41  		t.Errorf("PullRequests.List returned error: %v", err)
    42  	}
    43  
    44  	want := []*PullRequest{{Number: Int(1)}}
    45  	if !cmp.Equal(pulls, want) {
    46  		t.Errorf("PullRequests.List returned %+v, want %+v", pulls, want)
    47  	}
    48  
    49  	const methodName = "List"
    50  	testBadOptions(t, methodName, func() (err error) {
    51  		_, _, err = client.PullRequests.List(ctx, "\n", "\n", opts)
    52  		return err
    53  	})
    54  
    55  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    56  		got, resp, err := client.PullRequests.List(ctx, "o", "r", opts)
    57  		if got != nil {
    58  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    59  		}
    60  		return resp, err
    61  	})
    62  }
    63  
    64  func TestPullRequestsService_ListPullRequestsWithCommit(t *testing.T) {
    65  	client, mux, _, teardown := setup()
    66  	defer teardown()
    67  
    68  	mux.HandleFunc("/repos/o/r/commits/sha/pulls", func(w http.ResponseWriter, r *http.Request) {
    69  		testMethod(t, r, "GET")
    70  		testHeader(t, r, "Accept", mediaTypeListPullsOrBranchesForCommitPreview)
    71  		testFormValues(t, r, values{
    72  			"state":     "closed",
    73  			"head":      "h",
    74  			"base":      "b",
    75  			"sort":      "created",
    76  			"direction": "desc",
    77  			"page":      "2",
    78  		})
    79  		fmt.Fprint(w, `[{"number":1}]`)
    80  	})
    81  
    82  	opts := &PullRequestListOptions{"closed", "h", "b", "created", "desc", ListOptions{Page: 2}}
    83  	ctx := context.Background()
    84  	pulls, _, err := client.PullRequests.ListPullRequestsWithCommit(ctx, "o", "r", "sha", opts)
    85  	if err != nil {
    86  		t.Errorf("PullRequests.ListPullRequestsWithCommit returned error: %v", err)
    87  	}
    88  
    89  	want := []*PullRequest{{Number: Int(1)}}
    90  	if !cmp.Equal(pulls, want) {
    91  		t.Errorf("PullRequests.ListPullRequestsWithCommit returned %+v, want %+v", pulls, want)
    92  	}
    93  
    94  	const methodName = "ListPullRequestsWithCommit"
    95  	testBadOptions(t, methodName, func() (err error) {
    96  		_, _, err = client.PullRequests.ListPullRequestsWithCommit(ctx, "\n", "\n", "\n", opts)
    97  		return err
    98  	})
    99  
   100  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   101  		got, resp, err := client.PullRequests.ListPullRequestsWithCommit(ctx, "o", "r", "sha", opts)
   102  		if got != nil {
   103  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   104  		}
   105  		return resp, err
   106  	})
   107  }
   108  
   109  func TestPullRequestsService_List_invalidOwner(t *testing.T) {
   110  	client, _, _, teardown := setup()
   111  	defer teardown()
   112  
   113  	ctx := context.Background()
   114  	_, _, err := client.PullRequests.List(ctx, "%", "r", nil)
   115  	testURLParseError(t, err)
   116  }
   117  
   118  func TestPullRequestsService_Get(t *testing.T) {
   119  	client, mux, _, teardown := setup()
   120  	defer teardown()
   121  
   122  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   123  		testMethod(t, r, "GET")
   124  		fmt.Fprint(w, `{"number":1}`)
   125  	})
   126  
   127  	ctx := context.Background()
   128  	pull, _, err := client.PullRequests.Get(ctx, "o", "r", 1)
   129  	if err != nil {
   130  		t.Errorf("PullRequests.Get returned error: %v", err)
   131  	}
   132  
   133  	want := &PullRequest{Number: Int(1)}
   134  	if !cmp.Equal(pull, want) {
   135  		t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want)
   136  	}
   137  
   138  	const methodName = "Get"
   139  	testBadOptions(t, methodName, func() (err error) {
   140  		_, _, err = client.PullRequests.Get(ctx, "\n", "\n", -1)
   141  		return err
   142  	})
   143  
   144  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   145  		got, resp, err := client.PullRequests.Get(ctx, "o", "r", 1)
   146  		if got != nil {
   147  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   148  		}
   149  		return resp, err
   150  	})
   151  }
   152  
   153  func TestPullRequestsService_GetRaw_diff(t *testing.T) {
   154  	client, mux, _, teardown := setup()
   155  	defer teardown()
   156  
   157  	const rawStr = "@@diff content"
   158  
   159  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   160  		testMethod(t, r, "GET")
   161  		testHeader(t, r, "Accept", mediaTypeV3Diff)
   162  		fmt.Fprint(w, rawStr)
   163  	})
   164  
   165  	ctx := context.Background()
   166  	got, _, err := client.PullRequests.GetRaw(ctx, "o", "r", 1, RawOptions{Diff})
   167  	if err != nil {
   168  		t.Fatalf("PullRequests.GetRaw returned error: %v", err)
   169  	}
   170  	want := rawStr
   171  	if got != want {
   172  		t.Errorf("PullRequests.GetRaw returned %s want %s", got, want)
   173  	}
   174  
   175  	const methodName = "GetRaw"
   176  	testBadOptions(t, methodName, func() (err error) {
   177  		_, _, err = client.PullRequests.GetRaw(ctx, "\n", "\n", -1, RawOptions{Diff})
   178  		return err
   179  	})
   180  
   181  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   182  		got, resp, err := client.PullRequests.GetRaw(ctx, "o", "r", 1, RawOptions{Diff})
   183  		if got != "" {
   184  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   185  		}
   186  		return resp, err
   187  	})
   188  }
   189  
   190  func TestPullRequestsService_GetRaw_patch(t *testing.T) {
   191  	client, mux, _, teardown := setup()
   192  	defer teardown()
   193  
   194  	const rawStr = "@@patch content"
   195  
   196  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   197  		testMethod(t, r, "GET")
   198  		testHeader(t, r, "Accept", mediaTypeV3Patch)
   199  		fmt.Fprint(w, rawStr)
   200  	})
   201  
   202  	ctx := context.Background()
   203  	got, _, err := client.PullRequests.GetRaw(ctx, "o", "r", 1, RawOptions{Patch})
   204  	if err != nil {
   205  		t.Fatalf("PullRequests.GetRaw returned error: %v", err)
   206  	}
   207  	want := rawStr
   208  	if got != want {
   209  		t.Errorf("PullRequests.GetRaw returned %s want %s", got, want)
   210  	}
   211  }
   212  
   213  func TestPullRequestsService_GetRaw_invalid(t *testing.T) {
   214  	client, _, _, teardown := setup()
   215  	defer teardown()
   216  
   217  	ctx := context.Background()
   218  	_, _, err := client.PullRequests.GetRaw(ctx, "o", "r", 1, RawOptions{100})
   219  	if err == nil {
   220  		t.Fatal("PullRequests.GetRaw should return error")
   221  	}
   222  	if !strings.Contains(err.Error(), "unsupported raw type") {
   223  		t.Error("PullRequests.GetRaw should return unsupported raw type error")
   224  	}
   225  }
   226  
   227  func TestPullRequestsService_Get_links(t *testing.T) {
   228  	client, mux, _, teardown := setup()
   229  	defer teardown()
   230  
   231  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   232  		testMethod(t, r, "GET")
   233  		fmt.Fprint(w, `{
   234  			"number":1,
   235  			"_links":{
   236  				"self":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347"},
   237  				"html":{"href":"https://github.com/octocat/Hello-World/pull/1347"},
   238  				"issue":{"href":"https://api.github.com/repos/octocat/Hello-World/issues/1347"},
   239  				"comments":{"href":"https://api.github.com/repos/octocat/Hello-World/issues/1347/comments"},
   240  				"review_comments":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments"},
   241  				"review_comment":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"},
   242  				"commits":{"href":"https://api.github.com/repos/octocat/Hello-World/pulls/1347/commits"},
   243  				"statuses":{"href":"https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e"}
   244  				}
   245  			}`)
   246  	})
   247  
   248  	ctx := context.Background()
   249  	pull, _, err := client.PullRequests.Get(ctx, "o", "r", 1)
   250  	if err != nil {
   251  		t.Errorf("PullRequests.Get returned error: %v", err)
   252  	}
   253  
   254  	want := &PullRequest{
   255  		Number: Int(1),
   256  		Links: &PRLinks{
   257  			Self: &PRLink{
   258  				HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347"),
   259  			}, HTML: &PRLink{
   260  				HRef: String("https://github.com/octocat/Hello-World/pull/1347"),
   261  			}, Issue: &PRLink{
   262  				HRef: String("https://api.github.com/repos/octocat/Hello-World/issues/1347"),
   263  			}, Comments: &PRLink{
   264  				HRef: String("https://api.github.com/repos/octocat/Hello-World/issues/1347/comments"),
   265  			}, ReviewComments: &PRLink{
   266  				HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments"),
   267  			}, ReviewComment: &PRLink{
   268  				HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"),
   269  			}, Commits: &PRLink{
   270  				HRef: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347/commits"),
   271  			}, Statuses: &PRLink{
   272  				HRef: String("https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e"),
   273  			},
   274  		},
   275  	}
   276  	if !cmp.Equal(pull, want) {
   277  		t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want)
   278  	}
   279  }
   280  
   281  func TestPullRequestsService_Get_headAndBase(t *testing.T) {
   282  	client, mux, _, teardown := setup()
   283  	defer teardown()
   284  
   285  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   286  		testMethod(t, r, "GET")
   287  		fmt.Fprint(w, `{"number":1,"head":{"ref":"r2","repo":{"id":2}},"base":{"ref":"r1","repo":{"id":1}}}`)
   288  	})
   289  
   290  	ctx := context.Background()
   291  	pull, _, err := client.PullRequests.Get(ctx, "o", "r", 1)
   292  	if err != nil {
   293  		t.Errorf("PullRequests.Get returned error: %v", err)
   294  	}
   295  
   296  	want := &PullRequest{
   297  		Number: Int(1),
   298  		Head: &PullRequestBranch{
   299  			Ref:  String("r2"),
   300  			Repo: &Repository{ID: Int64(2)},
   301  		},
   302  		Base: &PullRequestBranch{
   303  			Ref:  String("r1"),
   304  			Repo: &Repository{ID: Int64(1)},
   305  		},
   306  	}
   307  	if !cmp.Equal(pull, want) {
   308  		t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want)
   309  	}
   310  }
   311  
   312  func TestPullRequestsService_Get_urlFields(t *testing.T) {
   313  	client, mux, _, teardown := setup()
   314  	defer teardown()
   315  
   316  	mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) {
   317  		testMethod(t, r, "GET")
   318  		fmt.Fprint(w, `{"number":1,
   319  			"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
   320  			"html_url": "https://github.com/octocat/Hello-World/pull/1347",
   321  			"issue_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
   322  			"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
   323  			"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
   324  			"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch",
   325  			"review_comments_url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments",
   326  			"review_comment_url": "https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"}`)
   327  	})
   328  
   329  	ctx := context.Background()
   330  	pull, _, err := client.PullRequests.Get(ctx, "o", "r", 1)
   331  	if err != nil {
   332  		t.Errorf("PullRequests.Get returned error: %v", err)
   333  	}
   334  
   335  	want := &PullRequest{
   336  		Number:            Int(1),
   337  		URL:               String("https://api.github.com/repos/octocat/Hello-World/pulls/1347"),
   338  		HTMLURL:           String("https://github.com/octocat/Hello-World/pull/1347"),
   339  		IssueURL:          String("https://api.github.com/repos/octocat/Hello-World/issues/1347"),
   340  		StatusesURL:       String("https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e"),
   341  		DiffURL:           String("https://github.com/octocat/Hello-World/pull/1347.diff"),
   342  		PatchURL:          String("https://github.com/octocat/Hello-World/pull/1347.patch"),
   343  		ReviewCommentsURL: String("https://api.github.com/repos/octocat/Hello-World/pulls/1347/comments"),
   344  		ReviewCommentURL:  String("https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"),
   345  	}
   346  
   347  	if !cmp.Equal(pull, want) {
   348  		t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want)
   349  	}
   350  }
   351  
   352  func TestPullRequestsService_Get_invalidOwner(t *testing.T) {
   353  	client, _, _, teardown := setup()
   354  	defer teardown()
   355  
   356  	ctx := context.Background()
   357  	_, _, err := client.PullRequests.Get(ctx, "%", "r", 1)
   358  	testURLParseError(t, err)
   359  }
   360  
   361  func TestPullRequestsService_Create(t *testing.T) {
   362  	client, mux, _, teardown := setup()
   363  	defer teardown()
   364  
   365  	input := &NewPullRequest{Title: String("t")}
   366  
   367  	mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) {
   368  		v := new(NewPullRequest)
   369  		json.NewDecoder(r.Body).Decode(v)
   370  
   371  		testMethod(t, r, "POST")
   372  		if !cmp.Equal(v, input) {
   373  			t.Errorf("Request body = %+v, want %+v", v, input)
   374  		}
   375  
   376  		fmt.Fprint(w, `{"number":1}`)
   377  	})
   378  
   379  	ctx := context.Background()
   380  	pull, _, err := client.PullRequests.Create(ctx, "o", "r", input)
   381  	if err != nil {
   382  		t.Errorf("PullRequests.Create returned error: %v", err)
   383  	}
   384  
   385  	want := &PullRequest{Number: Int(1)}
   386  	if !cmp.Equal(pull, want) {
   387  		t.Errorf("PullRequests.Create returned %+v, want %+v", pull, want)
   388  	}
   389  
   390  	const methodName = "Create"
   391  	testBadOptions(t, methodName, func() (err error) {
   392  		_, _, err = client.PullRequests.Create(ctx, "\n", "\n", input)
   393  		return err
   394  	})
   395  
   396  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   397  		got, resp, err := client.PullRequests.Create(ctx, "o", "r", input)
   398  		if got != nil {
   399  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   400  		}
   401  		return resp, err
   402  	})
   403  }
   404  
   405  func TestPullRequestsService_Create_invalidOwner(t *testing.T) {
   406  	client, _, _, teardown := setup()
   407  	defer teardown()
   408  
   409  	ctx := context.Background()
   410  	_, _, err := client.PullRequests.Create(ctx, "%", "r", nil)
   411  	testURLParseError(t, err)
   412  }
   413  
   414  func TestPullRequestsService_UpdateBranch(t *testing.T) {
   415  	client, mux, _, teardown := setup()
   416  	defer teardown()
   417  
   418  	mux.HandleFunc("/repos/o/r/pulls/1/update-branch", func(w http.ResponseWriter, r *http.Request) {
   419  		testMethod(t, r, "PUT")
   420  		testHeader(t, r, "Accept", mediaTypeUpdatePullRequestBranchPreview)
   421  		fmt.Fprint(w, `
   422  			{
   423  			  "message": "Updating pull request branch.",
   424  			  "url": "https://github.com/repos/o/r/pulls/1"
   425  			}`)
   426  	})
   427  
   428  	opts := &PullRequestBranchUpdateOptions{
   429  		ExpectedHeadSHA: String("s"),
   430  	}
   431  
   432  	ctx := context.Background()
   433  	pull, _, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, opts)
   434  	if err != nil {
   435  		t.Errorf("PullRequests.UpdateBranch returned error: %v", err)
   436  	}
   437  
   438  	want := &PullRequestBranchUpdateResponse{
   439  		Message: String("Updating pull request branch."),
   440  		URL:     String("https://github.com/repos/o/r/pulls/1"),
   441  	}
   442  
   443  	if !cmp.Equal(pull, want) {
   444  		t.Errorf("PullRequests.UpdateBranch returned %+v, want %+v", pull, want)
   445  	}
   446  
   447  	const methodName = "UpdateBranch"
   448  	testBadOptions(t, methodName, func() (err error) {
   449  		_, _, err = client.PullRequests.UpdateBranch(ctx, "\n", "\n", -1, opts)
   450  		return err
   451  	})
   452  
   453  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   454  		got, resp, err := client.PullRequests.UpdateBranch(ctx, "o", "r", 1, opts)
   455  		if got != nil {
   456  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   457  		}
   458  		return resp, err
   459  	})
   460  }
   461  
   462  func TestPullRequestsService_Edit(t *testing.T) {
   463  	client, mux, _, teardown := setup()
   464  	defer teardown()
   465  
   466  	tests := []struct {
   467  		input        *PullRequest
   468  		sendResponse string
   469  
   470  		wantUpdate string
   471  		want       *PullRequest
   472  	}{
   473  		{
   474  			input:        &PullRequest{Title: String("t")},
   475  			sendResponse: `{"number":1}`,
   476  			wantUpdate:   `{"title":"t"}`,
   477  			want:         &PullRequest{Number: Int(1)},
   478  		},
   479  		{
   480  			// base update
   481  			input:        &PullRequest{Base: &PullRequestBranch{Ref: String("master")}},
   482  			sendResponse: `{"number":1,"base":{"ref":"master"}}`,
   483  			wantUpdate:   `{"base":"master"}`,
   484  			want: &PullRequest{
   485  				Number: Int(1),
   486  				Base:   &PullRequestBranch{Ref: String("master")},
   487  			},
   488  		},
   489  	}
   490  
   491  	for i, tt := range tests {
   492  		madeRequest := false
   493  		mux.HandleFunc(fmt.Sprintf("/repos/o/r/pulls/%v", i), func(w http.ResponseWriter, r *http.Request) {
   494  			testMethod(t, r, "PATCH")
   495  			testBody(t, r, tt.wantUpdate+"\n")
   496  			io.WriteString(w, tt.sendResponse)
   497  			madeRequest = true
   498  		})
   499  
   500  		ctx := context.Background()
   501  		pull, _, err := client.PullRequests.Edit(ctx, "o", "r", i, tt.input)
   502  		if err != nil {
   503  			t.Errorf("%d: PullRequests.Edit returned error: %v", i, err)
   504  		}
   505  
   506  		if !cmp.Equal(pull, tt.want) {
   507  			t.Errorf("%d: PullRequests.Edit returned %+v, want %+v", i, pull, tt.want)
   508  		}
   509  
   510  		if !madeRequest {
   511  			t.Errorf("%d: PullRequest.Edit did not make the expected request", i)
   512  		}
   513  
   514  		const methodName = "Edit"
   515  		testBadOptions(t, methodName, func() (err error) {
   516  			_, _, err = client.PullRequests.Edit(ctx, "\n", "\n", -i, tt.input)
   517  			return err
   518  		})
   519  	}
   520  }
   521  
   522  func TestPullRequestsService_Edit_invalidOwner(t *testing.T) {
   523  	client, _, _, teardown := setup()
   524  	defer teardown()
   525  
   526  	ctx := context.Background()
   527  	_, _, err := client.PullRequests.Edit(ctx, "%", "r", 1, &PullRequest{})
   528  	testURLParseError(t, err)
   529  }
   530  
   531  func TestPullRequestsService_ListCommits(t *testing.T) {
   532  	client, mux, _, teardown := setup()
   533  	defer teardown()
   534  
   535  	mux.HandleFunc("/repos/o/r/pulls/1/commits", func(w http.ResponseWriter, r *http.Request) {
   536  		testMethod(t, r, "GET")
   537  		testFormValues(t, r, values{"page": "2"})
   538  		fmt.Fprint(w, `
   539  			[
   540  			  {
   541  			    "sha": "3",
   542  			    "parents": [
   543  			      {
   544  			        "sha": "2"
   545  			      }
   546  			    ]
   547  			  },
   548  			  {
   549  			    "sha": "2",
   550  			    "parents": [
   551  			      {
   552  			        "sha": "1"
   553  			      }
   554  			    ]
   555  			  }
   556  			]`)
   557  	})
   558  
   559  	opts := &ListOptions{Page: 2}
   560  	ctx := context.Background()
   561  	commits, _, err := client.PullRequests.ListCommits(ctx, "o", "r", 1, opts)
   562  	if err != nil {
   563  		t.Errorf("PullRequests.ListCommits returned error: %v", err)
   564  	}
   565  
   566  	want := []*RepositoryCommit{
   567  		{
   568  			SHA: String("3"),
   569  			Parents: []*Commit{
   570  				{
   571  					SHA: String("2"),
   572  				},
   573  			},
   574  		},
   575  		{
   576  			SHA: String("2"),
   577  			Parents: []*Commit{
   578  				{
   579  					SHA: String("1"),
   580  				},
   581  			},
   582  		},
   583  	}
   584  	if !cmp.Equal(commits, want) {
   585  		t.Errorf("PullRequests.ListCommits returned %+v, want %+v", commits, want)
   586  	}
   587  
   588  	const methodName = "ListCommits"
   589  	testBadOptions(t, methodName, func() (err error) {
   590  		_, _, err = client.PullRequests.ListCommits(ctx, "\n", "\n", -1, opts)
   591  		return err
   592  	})
   593  
   594  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   595  		got, resp, err := client.PullRequests.ListCommits(ctx, "o", "r", 1, opts)
   596  		if got != nil {
   597  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   598  		}
   599  		return resp, err
   600  	})
   601  }
   602  
   603  func TestPullRequestsService_ListFiles(t *testing.T) {
   604  	client, mux, _, teardown := setup()
   605  	defer teardown()
   606  
   607  	mux.HandleFunc("/repos/o/r/pulls/1/files", func(w http.ResponseWriter, r *http.Request) {
   608  		testMethod(t, r, "GET")
   609  		testFormValues(t, r, values{"page": "2"})
   610  		fmt.Fprint(w, `
   611  			[
   612  			  {
   613  			    "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
   614  			    "filename": "file1.txt",
   615  			    "status": "added",
   616  			    "additions": 103,
   617  			    "deletions": 21,
   618  			    "changes": 124,
   619  			    "patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
   620  			  },
   621  			  {
   622  			    "sha": "f61aebed695e2e4193db5e6dcb09b5b57875f334",
   623  			    "filename": "file2.txt",
   624  			    "status": "modified",
   625  			    "additions": 5,
   626  			    "deletions": 3,
   627  			    "changes": 103,
   628  			    "patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
   629  			  }
   630  			]`)
   631  	})
   632  
   633  	opts := &ListOptions{Page: 2}
   634  	ctx := context.Background()
   635  	commitFiles, _, err := client.PullRequests.ListFiles(ctx, "o", "r", 1, opts)
   636  	if err != nil {
   637  		t.Errorf("PullRequests.ListFiles returned error: %v", err)
   638  	}
   639  
   640  	want := []*CommitFile{
   641  		{
   642  			SHA:       String("6dcb09b5b57875f334f61aebed695e2e4193db5e"),
   643  			Filename:  String("file1.txt"),
   644  			Additions: Int(103),
   645  			Deletions: Int(21),
   646  			Changes:   Int(124),
   647  			Status:    String("added"),
   648  			Patch:     String("@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"),
   649  		},
   650  		{
   651  			SHA:       String("f61aebed695e2e4193db5e6dcb09b5b57875f334"),
   652  			Filename:  String("file2.txt"),
   653  			Additions: Int(5),
   654  			Deletions: Int(3),
   655  			Changes:   Int(103),
   656  			Status:    String("modified"),
   657  			Patch:     String("@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"),
   658  		},
   659  	}
   660  
   661  	if !cmp.Equal(commitFiles, want) {
   662  		t.Errorf("PullRequests.ListFiles returned %+v, want %+v", commitFiles, want)
   663  	}
   664  
   665  	const methodName = "ListFiles"
   666  	testBadOptions(t, methodName, func() (err error) {
   667  		_, _, err = client.PullRequests.ListFiles(ctx, "\n", "\n", -1, opts)
   668  		return err
   669  	})
   670  
   671  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   672  		got, resp, err := client.PullRequests.ListFiles(ctx, "o", "r", 1, opts)
   673  		if got != nil {
   674  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   675  		}
   676  		return resp, err
   677  	})
   678  }
   679  
   680  func TestPullRequestsService_IsMerged(t *testing.T) {
   681  	client, mux, _, teardown := setup()
   682  	defer teardown()
   683  
   684  	mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) {
   685  		testMethod(t, r, "GET")
   686  		w.WriteHeader(http.StatusNoContent)
   687  	})
   688  
   689  	ctx := context.Background()
   690  	isMerged, _, err := client.PullRequests.IsMerged(ctx, "o", "r", 1)
   691  	if err != nil {
   692  		t.Errorf("PullRequests.IsMerged returned error: %v", err)
   693  	}
   694  
   695  	want := true
   696  	if !cmp.Equal(isMerged, want) {
   697  		t.Errorf("PullRequests.IsMerged returned %+v, want %+v", isMerged, want)
   698  	}
   699  
   700  	const methodName = "IsMerged"
   701  	testBadOptions(t, methodName, func() (err error) {
   702  		_, _, err = client.PullRequests.IsMerged(ctx, "\n", "\n", -1)
   703  		return err
   704  	})
   705  
   706  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   707  		got, resp, err := client.PullRequests.IsMerged(ctx, "o", "r", 1)
   708  		if got {
   709  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want false", methodName, got)
   710  		}
   711  		return resp, err
   712  	})
   713  }
   714  
   715  func TestPullRequestsService_Merge(t *testing.T) {
   716  	client, mux, _, teardown := setup()
   717  	defer teardown()
   718  
   719  	mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) {
   720  		testMethod(t, r, "PUT")
   721  		fmt.Fprint(w, `
   722  			{
   723  			  "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
   724  			  "merged": true,
   725  			  "message": "Pull Request successfully merged"
   726  			}`)
   727  	})
   728  
   729  	options := &PullRequestOptions{MergeMethod: "rebase"}
   730  	ctx := context.Background()
   731  	merge, _, err := client.PullRequests.Merge(ctx, "o", "r", 1, "merging pull request", options)
   732  	if err != nil {
   733  		t.Errorf("PullRequests.Merge returned error: %v", err)
   734  	}
   735  
   736  	want := &PullRequestMergeResult{
   737  		SHA:     String("6dcb09b5b57875f334f61aebed695e2e4193db5e"),
   738  		Merged:  Bool(true),
   739  		Message: String("Pull Request successfully merged"),
   740  	}
   741  	if !cmp.Equal(merge, want) {
   742  		t.Errorf("PullRequests.Merge returned %+v, want %+v", merge, want)
   743  	}
   744  
   745  	const methodName = "Merge"
   746  	testBadOptions(t, methodName, func() (err error) {
   747  		_, _, err = client.PullRequests.Merge(ctx, "\n", "\n", -1, "\n", options)
   748  		return err
   749  	})
   750  
   751  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   752  		got, resp, err := client.PullRequests.Merge(ctx, "o", "r", 1, "merging pull request", options)
   753  		if got != nil {
   754  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   755  		}
   756  		return resp, err
   757  	})
   758  }
   759  
   760  // Test that different merge options produce expected PUT requests. See issue https://github.com/google/go-github/issues/500.
   761  func TestPullRequestsService_Merge_options(t *testing.T) {
   762  	client, mux, _, teardown := setup()
   763  	defer teardown()
   764  
   765  	tests := []struct {
   766  		options  *PullRequestOptions
   767  		wantBody string
   768  	}{
   769  		{
   770  			options:  nil,
   771  			wantBody: `{"commit_message":"merging pull request"}`,
   772  		},
   773  		{
   774  			options:  &PullRequestOptions{},
   775  			wantBody: `{"commit_message":"merging pull request"}`,
   776  		},
   777  		{
   778  			options:  &PullRequestOptions{MergeMethod: "rebase"},
   779  			wantBody: `{"commit_message":"merging pull request","merge_method":"rebase"}`,
   780  		},
   781  		{
   782  			options:  &PullRequestOptions{SHA: "6dcb09b5b57875f334f61aebed695e2e4193db5e"},
   783  			wantBody: `{"commit_message":"merging pull request","sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e"}`,
   784  		},
   785  		{
   786  			options: &PullRequestOptions{
   787  				CommitTitle: "Extra detail",
   788  				SHA:         "6dcb09b5b57875f334f61aebed695e2e4193db5e",
   789  				MergeMethod: "squash",
   790  			},
   791  			wantBody: `{"commit_message":"merging pull request","commit_title":"Extra detail","merge_method":"squash","sha":"6dcb09b5b57875f334f61aebed695e2e4193db5e"}`,
   792  		},
   793  		{
   794  			options: &PullRequestOptions{
   795  				DontDefaultIfBlank: true,
   796  			},
   797  			wantBody: `{"commit_message":"merging pull request"}`,
   798  		},
   799  	}
   800  
   801  	for i, test := range tests {
   802  		madeRequest := false
   803  		mux.HandleFunc(fmt.Sprintf("/repos/o/r/pulls/%d/merge", i), func(w http.ResponseWriter, r *http.Request) {
   804  			testMethod(t, r, "PUT")
   805  			testBody(t, r, test.wantBody+"\n")
   806  			madeRequest = true
   807  		})
   808  		ctx := context.Background()
   809  		_, _, _ = client.PullRequests.Merge(ctx, "o", "r", i, "merging pull request", test.options)
   810  		if !madeRequest {
   811  			t.Errorf("%d: PullRequests.Merge(%#v): expected request was not made", i, test.options)
   812  		}
   813  	}
   814  }
   815  
   816  func TestPullRequestsService_Merge_Blank_Message(t *testing.T) {
   817  	client, mux, _, teardown := setup()
   818  	defer teardown()
   819  	madeRequest := false
   820  	expectedBody := ""
   821  	mux.HandleFunc("/repos/o/r/pulls/1/merge", func(w http.ResponseWriter, r *http.Request) {
   822  		testMethod(t, r, "PUT")
   823  		testBody(t, r, expectedBody+"\n")
   824  		madeRequest = true
   825  	})
   826  
   827  	ctx := context.Background()
   828  	expectedBody = `{}`
   829  	_, _, _ = client.PullRequests.Merge(ctx, "o", "r", 1, "", nil)
   830  	if !madeRequest {
   831  		t.Error("TestPullRequestsService_Merge_Blank_Message #1 did not make request")
   832  	}
   833  
   834  	madeRequest = false
   835  	opts := PullRequestOptions{
   836  		DontDefaultIfBlank: true,
   837  	}
   838  	expectedBody = `{"commit_message":""}`
   839  	_, _, _ = client.PullRequests.Merge(ctx, "o", "r", 1, "", &opts)
   840  	if !madeRequest {
   841  		t.Error("TestPullRequestsService_Merge_Blank_Message #2 did not make request")
   842  	}
   843  }
   844  
   845  func TestPullRequestMergeRequest_Marshal(t *testing.T) {
   846  	testJSONMarshal(t, &pullRequestMergeRequest{}, "{}")
   847  
   848  	u := &pullRequestMergeRequest{
   849  		CommitMessage: String("cm"),
   850  		CommitTitle:   "ct",
   851  		MergeMethod:   "mm",
   852  		SHA:           "sha",
   853  	}
   854  
   855  	want := `{
   856  		"commit_message": "cm",
   857  		"commit_title": "ct",
   858  		"merge_method": "mm",
   859  		"sha": "sha"
   860  	}`
   861  
   862  	testJSONMarshal(t, u, want)
   863  }
   864  
   865  func TestPullRequestMergeResult_Marshal(t *testing.T) {
   866  	testJSONMarshal(t, &PullRequestMergeResult{}, "{}")
   867  
   868  	u := &PullRequestMergeResult{
   869  		SHA:     String("sha"),
   870  		Merged:  Bool(false),
   871  		Message: String("msg"),
   872  	}
   873  
   874  	want := `{
   875  		"sha": "sha",
   876  		"merged": false,
   877  		"message": "msg"
   878  	}`
   879  
   880  	testJSONMarshal(t, u, want)
   881  }
   882  
   883  func TestPullRequestUpdate_Marshal(t *testing.T) {
   884  	testJSONMarshal(t, &pullRequestUpdate{}, "{}")
   885  
   886  	u := &pullRequestUpdate{
   887  		Title:               String("title"),
   888  		Body:                String("body"),
   889  		State:               String("state"),
   890  		Base:                String("base"),
   891  		MaintainerCanModify: Bool(false),
   892  	}
   893  
   894  	want := `{
   895  		"title": "title",
   896  		"body": "body",
   897  		"state": "state",
   898  		"base": "base",
   899  		"maintainer_can_modify": false
   900  	}`
   901  
   902  	testJSONMarshal(t, u, want)
   903  }
   904  
   905  func TestPullRequestBranchUpdateResponse_Marshal(t *testing.T) {
   906  	testJSONMarshal(t, &PullRequestBranchUpdateResponse{}, "{}")
   907  
   908  	u := &PullRequestBranchUpdateResponse{
   909  		Message: String("message"),
   910  		URL:     String("url"),
   911  	}
   912  
   913  	want := `{
   914  		"message": "message",
   915  		"url": "url"
   916  	}`
   917  
   918  	testJSONMarshal(t, u, want)
   919  }
   920  
   921  func TestPullRequestBranchUpdateOptions_Marshal(t *testing.T) {
   922  	testJSONMarshal(t, &PullRequestBranchUpdateOptions{}, "{}")
   923  
   924  	u := &PullRequestBranchUpdateOptions{
   925  		ExpectedHeadSHA: String("eh"),
   926  	}
   927  
   928  	want := `{
   929  		"expected_head_sha": "eh"
   930  	}`
   931  
   932  	testJSONMarshal(t, u, want)
   933  }
   934  
   935  func TestNewPullRequest_Marshal(t *testing.T) {
   936  	testJSONMarshal(t, &NewPullRequest{}, "{}")
   937  
   938  	u := &NewPullRequest{
   939  		Title:               String("eh"),
   940  		Head:                String("eh"),
   941  		Base:                String("eh"),
   942  		Body:                String("eh"),
   943  		Issue:               Int(1),
   944  		MaintainerCanModify: Bool(false),
   945  		Draft:               Bool(false),
   946  	}
   947  
   948  	want := `{
   949  		"title": "eh",
   950  		"head": "eh",
   951  		"base": "eh",
   952  		"body": "eh",
   953  		"issue": 1,
   954  		"maintainer_can_modify": false,
   955  		"draft": false
   956  	}`
   957  
   958  	testJSONMarshal(t, u, want)
   959  }
   960  
   961  func TestPullRequestBranch_Marshal(t *testing.T) {
   962  	testJSONMarshal(t, &PullRequestBranch{}, "{}")
   963  
   964  	u := &PullRequestBranch{
   965  		Label: String("label"),
   966  		Ref:   String("ref"),
   967  		SHA:   String("sha"),
   968  		Repo:  &Repository{ID: Int64(1)},
   969  		User: &User{
   970  			Login:           String("l"),
   971  			ID:              Int64(1),
   972  			URL:             String("u"),
   973  			AvatarURL:       String("a"),
   974  			GravatarID:      String("g"),
   975  			Name:            String("n"),
   976  			Company:         String("c"),
   977  			Blog:            String("b"),
   978  			Location:        String("l"),
   979  			Email:           String("e"),
   980  			Hireable:        Bool(true),
   981  			Bio:             String("b"),
   982  			TwitterUsername: String("t"),
   983  			PublicRepos:     Int(1),
   984  			Followers:       Int(1),
   985  			Following:       Int(1),
   986  			CreatedAt:       &Timestamp{referenceTime},
   987  			SuspendedAt:     &Timestamp{referenceTime},
   988  		},
   989  	}
   990  
   991  	want := `{
   992  		"label": "label",
   993  		"ref": "ref",
   994  		"sha": "sha",
   995  		"repo": {
   996  			"id": 1
   997  		},
   998  		"user": {
   999  			"login": "l",
  1000  			"id": 1,
  1001  			"avatar_url": "a",
  1002  			"gravatar_id": "g",
  1003  			"name": "n",
  1004  			"company": "c",
  1005  			"blog": "b",
  1006  			"location": "l",
  1007  			"email": "e",
  1008  			"hireable": true,
  1009  			"bio": "b",
  1010  			"twitter_username": "t",
  1011  			"public_repos": 1,
  1012  			"followers": 1,
  1013  			"following": 1,
  1014  			"created_at": ` + referenceTimeStr + `,
  1015  			"suspended_at": ` + referenceTimeStr + `,
  1016  			"url": "u"
  1017  		}
  1018  	}`
  1019  
  1020  	testJSONMarshal(t, u, want)
  1021  }
  1022  
  1023  func TestPRLink_Marshal(t *testing.T) {
  1024  	testJSONMarshal(t, &PRLink{}, "{}")
  1025  
  1026  	u := &PRLink{
  1027  		HRef: String("href"),
  1028  	}
  1029  
  1030  	want := `{
  1031  		"href": "href"
  1032  	}`
  1033  
  1034  	testJSONMarshal(t, u, want)
  1035  }
  1036  
  1037  func TestPRLinks_Marshal(t *testing.T) {
  1038  	testJSONMarshal(t, &PRLinks{}, "{}")
  1039  
  1040  	u := &PRLinks{
  1041  		Self: &PRLink{
  1042  			HRef: String("href"),
  1043  		},
  1044  		HTML: &PRLink{
  1045  			HRef: String("href"),
  1046  		},
  1047  		Issue: &PRLink{
  1048  			HRef: String("href"),
  1049  		},
  1050  		Comments: &PRLink{
  1051  			HRef: String("href"),
  1052  		},
  1053  		ReviewComments: &PRLink{
  1054  			HRef: String("href"),
  1055  		},
  1056  		ReviewComment: &PRLink{
  1057  			HRef: String("href"),
  1058  		},
  1059  		Commits: &PRLink{
  1060  			HRef: String("href"),
  1061  		},
  1062  		Statuses: &PRLink{
  1063  			HRef: String("href"),
  1064  		},
  1065  	}
  1066  
  1067  	want := `{
  1068  		"self": {
  1069  			"href": "href"
  1070  		},
  1071  		"html": {
  1072  			"href": "href"
  1073  		},
  1074  		"issue": {
  1075  			"href": "href"
  1076  		},
  1077  		"comments": {
  1078  			"href": "href"
  1079  		},
  1080  		"review_comments": {
  1081  			"href": "href"
  1082  		},
  1083  		"review_comment": {
  1084  			"href": "href"
  1085  		},
  1086  		"commits": {
  1087  			"href": "href"
  1088  		},
  1089  		"statuses": {
  1090  			"href": "href"
  1091  		}
  1092  	}`
  1093  
  1094  	testJSONMarshal(t, u, want)
  1095  }
  1096  
  1097  func TestPullRequestAutoMerge_Marshal(t *testing.T) {
  1098  	testJSONMarshal(t, &PullRequestAutoMerge{}, "{}")
  1099  
  1100  	u := &PullRequestAutoMerge{
  1101  		EnabledBy: &User{
  1102  			Login:           String("l"),
  1103  			ID:              Int64(1),
  1104  			URL:             String("u"),
  1105  			AvatarURL:       String("a"),
  1106  			GravatarID:      String("g"),
  1107  			Name:            String("n"),
  1108  			Company:         String("c"),
  1109  			Blog:            String("b"),
  1110  			Location:        String("l"),
  1111  			Email:           String("e"),
  1112  			Hireable:        Bool(true),
  1113  			Bio:             String("b"),
  1114  			TwitterUsername: String("t"),
  1115  			PublicRepos:     Int(1),
  1116  			Followers:       Int(1),
  1117  			Following:       Int(1),
  1118  			CreatedAt:       &Timestamp{referenceTime},
  1119  			SuspendedAt:     &Timestamp{referenceTime},
  1120  		},
  1121  		MergeMethod:   String("mm"),
  1122  		CommitTitle:   String("ct"),
  1123  		CommitMessage: String("cm"),
  1124  	}
  1125  
  1126  	want := `{
  1127  		"enabled_by": {
  1128  			"login": "l",
  1129  			"id": 1,
  1130  			"avatar_url": "a",
  1131  			"gravatar_id": "g",
  1132  			"name": "n",
  1133  			"company": "c",
  1134  			"blog": "b",
  1135  			"location": "l",
  1136  			"email": "e",
  1137  			"hireable": true,
  1138  			"bio": "b",
  1139  			"twitter_username": "t",
  1140  			"public_repos": 1,
  1141  			"followers": 1,
  1142  			"following": 1,
  1143  			"created_at": ` + referenceTimeStr + `,
  1144  			"suspended_at": ` + referenceTimeStr + `,
  1145  			"url": "u"
  1146  		},
  1147  		"merge_method": "mm",
  1148  		"commit_title": "ct",
  1149  		"commit_message": "cm"
  1150  	}`
  1151  
  1152  	testJSONMarshal(t, u, want)
  1153  }
  1154  
  1155  func TestPullRequest_Marshal(t *testing.T) {
  1156  	testJSONMarshal(t, &PullRequest{}, "{}")
  1157  
  1158  	u := &PullRequest{
  1159  		ID:        Int64(1),
  1160  		Number:    Int(1),
  1161  		State:     String("state"),
  1162  		Locked:    Bool(false),
  1163  		Title:     String("title"),
  1164  		Body:      String("body"),
  1165  		CreatedAt: &referenceTime,
  1166  		UpdatedAt: &referenceTime,
  1167  		ClosedAt:  &referenceTime,
  1168  		MergedAt:  &referenceTime,
  1169  		Labels:    []*Label{{ID: Int64(1)}},
  1170  		User: &User{
  1171  			Login:           String("l"),
  1172  			ID:              Int64(1),
  1173  			URL:             String("u"),
  1174  			AvatarURL:       String("a"),
  1175  			GravatarID:      String("g"),
  1176  			Name:            String("n"),
  1177  			Company:         String("c"),
  1178  			Blog:            String("b"),
  1179  			Location:        String("l"),
  1180  			Email:           String("e"),
  1181  			Hireable:        Bool(true),
  1182  			Bio:             String("b"),
  1183  			TwitterUsername: String("t"),
  1184  			PublicRepos:     Int(1),
  1185  			Followers:       Int(1),
  1186  			Following:       Int(1),
  1187  			CreatedAt:       &Timestamp{referenceTime},
  1188  			SuspendedAt:     &Timestamp{referenceTime},
  1189  		},
  1190  		Draft:          Bool(false),
  1191  		Merged:         Bool(false),
  1192  		Mergeable:      Bool(false),
  1193  		MergeableState: String("ms"),
  1194  		MergedBy: &User{
  1195  			Login:           String("l"),
  1196  			ID:              Int64(1),
  1197  			URL:             String("u"),
  1198  			AvatarURL:       String("a"),
  1199  			GravatarID:      String("g"),
  1200  			Name:            String("n"),
  1201  			Company:         String("c"),
  1202  			Blog:            String("b"),
  1203  			Location:        String("l"),
  1204  			Email:           String("e"),
  1205  			Hireable:        Bool(true),
  1206  			Bio:             String("b"),
  1207  			TwitterUsername: String("t"),
  1208  			PublicRepos:     Int(1),
  1209  			Followers:       Int(1),
  1210  			Following:       Int(1),
  1211  			CreatedAt:       &Timestamp{referenceTime},
  1212  			SuspendedAt:     &Timestamp{referenceTime},
  1213  		},
  1214  		MergeCommitSHA:    String("mcs"),
  1215  		Rebaseable:        Bool(false),
  1216  		Comments:          Int(1),
  1217  		Commits:           Int(1),
  1218  		Additions:         Int(1),
  1219  		Deletions:         Int(1),
  1220  		ChangedFiles:      Int(1),
  1221  		URL:               String("url"),
  1222  		HTMLURL:           String("hurl"),
  1223  		IssueURL:          String("iurl"),
  1224  		StatusesURL:       String("surl"),
  1225  		DiffURL:           String("durl"),
  1226  		PatchURL:          String("purl"),
  1227  		CommitsURL:        String("curl"),
  1228  		CommentsURL:       String("comurl"),
  1229  		ReviewCommentsURL: String("rcurls"),
  1230  		ReviewCommentURL:  String("rcurl"),
  1231  		ReviewComments:    Int(1),
  1232  		Assignee: &User{
  1233  			Login:           String("l"),
  1234  			ID:              Int64(1),
  1235  			URL:             String("u"),
  1236  			AvatarURL:       String("a"),
  1237  			GravatarID:      String("g"),
  1238  			Name:            String("n"),
  1239  			Company:         String("c"),
  1240  			Blog:            String("b"),
  1241  			Location:        String("l"),
  1242  			Email:           String("e"),
  1243  			Hireable:        Bool(true),
  1244  			Bio:             String("b"),
  1245  			TwitterUsername: String("t"),
  1246  			PublicRepos:     Int(1),
  1247  			Followers:       Int(1),
  1248  			Following:       Int(1),
  1249  			CreatedAt:       &Timestamp{referenceTime},
  1250  			SuspendedAt:     &Timestamp{referenceTime},
  1251  		},
  1252  		Assignees: []*User{
  1253  			{
  1254  				Login:           String("l"),
  1255  				ID:              Int64(1),
  1256  				URL:             String("u"),
  1257  				AvatarURL:       String("a"),
  1258  				GravatarID:      String("g"),
  1259  				Name:            String("n"),
  1260  				Company:         String("c"),
  1261  				Blog:            String("b"),
  1262  				Location:        String("l"),
  1263  				Email:           String("e"),
  1264  				Hireable:        Bool(true),
  1265  				Bio:             String("b"),
  1266  				TwitterUsername: String("t"),
  1267  				PublicRepos:     Int(1),
  1268  				Followers:       Int(1),
  1269  				Following:       Int(1),
  1270  				CreatedAt:       &Timestamp{referenceTime},
  1271  				SuspendedAt:     &Timestamp{referenceTime},
  1272  			},
  1273  		},
  1274  		Milestone:           &Milestone{ID: Int64(1)},
  1275  		MaintainerCanModify: Bool(true),
  1276  		AuthorAssociation:   String("aa"),
  1277  		NodeID:              String("nid"),
  1278  		RequestedReviewers: []*User{
  1279  			{
  1280  				Login:           String("l"),
  1281  				ID:              Int64(1),
  1282  				URL:             String("u"),
  1283  				AvatarURL:       String("a"),
  1284  				GravatarID:      String("g"),
  1285  				Name:            String("n"),
  1286  				Company:         String("c"),
  1287  				Blog:            String("b"),
  1288  				Location:        String("l"),
  1289  				Email:           String("e"),
  1290  				Hireable:        Bool(true),
  1291  				Bio:             String("b"),
  1292  				TwitterUsername: String("t"),
  1293  				PublicRepos:     Int(1),
  1294  				Followers:       Int(1),
  1295  				Following:       Int(1),
  1296  				CreatedAt:       &Timestamp{referenceTime},
  1297  				SuspendedAt:     &Timestamp{referenceTime},
  1298  			},
  1299  		},
  1300  		AutoMerge: &PullRequestAutoMerge{
  1301  			EnabledBy: &User{
  1302  				Login:           String("l"),
  1303  				ID:              Int64(1),
  1304  				URL:             String("u"),
  1305  				AvatarURL:       String("a"),
  1306  				GravatarID:      String("g"),
  1307  				Name:            String("n"),
  1308  				Company:         String("c"),
  1309  				Blog:            String("b"),
  1310  				Location:        String("l"),
  1311  				Email:           String("e"),
  1312  				Hireable:        Bool(true),
  1313  				Bio:             String("b"),
  1314  				TwitterUsername: String("t"),
  1315  				PublicRepos:     Int(1),
  1316  				Followers:       Int(1),
  1317  				Following:       Int(1),
  1318  				CreatedAt:       &Timestamp{referenceTime},
  1319  				SuspendedAt:     &Timestamp{referenceTime},
  1320  			},
  1321  			MergeMethod:   String("mm"),
  1322  			CommitTitle:   String("ct"),
  1323  			CommitMessage: String("cm"),
  1324  		},
  1325  		RequestedTeams: []*Team{{ID: Int64(1)}},
  1326  		Links: &PRLinks{
  1327  			Self: &PRLink{
  1328  				HRef: String("href"),
  1329  			},
  1330  			HTML: &PRLink{
  1331  				HRef: String("href"),
  1332  			},
  1333  			Issue: &PRLink{
  1334  				HRef: String("href"),
  1335  			},
  1336  			Comments: &PRLink{
  1337  				HRef: String("href"),
  1338  			},
  1339  			ReviewComments: &PRLink{
  1340  				HRef: String("href"),
  1341  			},
  1342  			ReviewComment: &PRLink{
  1343  				HRef: String("href"),
  1344  			},
  1345  			Commits: &PRLink{
  1346  				HRef: String("href"),
  1347  			},
  1348  			Statuses: &PRLink{
  1349  				HRef: String("href"),
  1350  			},
  1351  		},
  1352  		Head: &PullRequestBranch{
  1353  			Ref:  String("r2"),
  1354  			Repo: &Repository{ID: Int64(2)},
  1355  		},
  1356  		Base: &PullRequestBranch{
  1357  			Ref:  String("r2"),
  1358  			Repo: &Repository{ID: Int64(2)},
  1359  		},
  1360  		ActiveLockReason: String("alr"),
  1361  	}
  1362  
  1363  	want := `{
  1364  		"id": 1,
  1365  		"number": 1,
  1366  		"state": "state",
  1367  		"locked": false,
  1368  		"title": "title",
  1369  		"body": "body",
  1370  		"created_at": ` + referenceTimeStr + `,
  1371  		"updated_at": ` + referenceTimeStr + `,
  1372  		"closed_at": ` + referenceTimeStr + `,
  1373  		"merged_at": ` + referenceTimeStr + `,
  1374  		"labels": [
  1375  			{
  1376  				"id": 1
  1377  			}
  1378  		],
  1379  		"user": {
  1380  			"login": "l",
  1381  			"id": 1,
  1382  			"avatar_url": "a",
  1383  			"gravatar_id": "g",
  1384  			"name": "n",
  1385  			"company": "c",
  1386  			"blog": "b",
  1387  			"location": "l",
  1388  			"email": "e",
  1389  			"hireable": true,
  1390  			"bio": "b",
  1391  			"twitter_username": "t",
  1392  			"public_repos": 1,
  1393  			"followers": 1,
  1394  			"following": 1,
  1395  			"created_at": ` + referenceTimeStr + `,
  1396  			"suspended_at": ` + referenceTimeStr + `,
  1397  			"url": "u"
  1398  		},
  1399  		"draft": false,
  1400  		"merged": false,
  1401  		"mergeable": false,
  1402  		"mergeable_state": "ms",
  1403  		"merged_by": {
  1404  			"login": "l",
  1405  			"id": 1,
  1406  			"avatar_url": "a",
  1407  			"gravatar_id": "g",
  1408  			"name": "n",
  1409  			"company": "c",
  1410  			"blog": "b",
  1411  			"location": "l",
  1412  			"email": "e",
  1413  			"hireable": true,
  1414  			"bio": "b",
  1415  			"twitter_username": "t",
  1416  			"public_repos": 1,
  1417  			"followers": 1,
  1418  			"following": 1,
  1419  			"created_at": ` + referenceTimeStr + `,
  1420  			"suspended_at": ` + referenceTimeStr + `,
  1421  			"url": "u"
  1422  		},
  1423  		"merge_commit_sha": "mcs",
  1424  		"rebaseable": false,
  1425  		"comments": 1,
  1426  		"commits": 1,
  1427  		"additions": 1,
  1428  		"deletions": 1,
  1429  		"changed_files": 1,
  1430  		"url": "url",
  1431  		"html_url": "hurl",
  1432  		"issue_url": "iurl",
  1433  		"statuses_url": "surl",
  1434  		"diff_url": "durl",
  1435  		"patch_url": "purl",
  1436  		"commits_url": "curl",
  1437  		"comments_url": "comurl",
  1438  		"review_comments_url": "rcurls",
  1439  		"review_comment_url": "rcurl",
  1440  		"review_comments": 1,
  1441  		"assignee": {
  1442  			"login": "l",
  1443  			"id": 1,
  1444  			"avatar_url": "a",
  1445  			"gravatar_id": "g",
  1446  			"name": "n",
  1447  			"company": "c",
  1448  			"blog": "b",
  1449  			"location": "l",
  1450  			"email": "e",
  1451  			"hireable": true,
  1452  			"bio": "b",
  1453  			"twitter_username": "t",
  1454  			"public_repos": 1,
  1455  			"followers": 1,
  1456  			"following": 1,
  1457  			"created_at": ` + referenceTimeStr + `,
  1458  			"suspended_at": ` + referenceTimeStr + `,
  1459  			"url": "u"
  1460  		},
  1461  		"assignees": [
  1462  			{
  1463  				"login": "l",
  1464  				"id": 1,
  1465  				"avatar_url": "a",
  1466  				"gravatar_id": "g",
  1467  				"name": "n",
  1468  				"company": "c",
  1469  				"blog": "b",
  1470  				"location": "l",
  1471  				"email": "e",
  1472  				"hireable": true,
  1473  				"bio": "b",
  1474  				"twitter_username": "t",
  1475  				"public_repos": 1,
  1476  				"followers": 1,
  1477  				"following": 1,
  1478  				"created_at": ` + referenceTimeStr + `,
  1479  				"suspended_at": ` + referenceTimeStr + `,
  1480  				"url": "u"
  1481  			}
  1482  		],
  1483  		"milestone": {
  1484  			"id": 1
  1485  		},
  1486  		"maintainer_can_modify": true,
  1487  		"author_association": "aa",
  1488  		"node_id": "nid",
  1489  		"requested_reviewers": [
  1490  			{
  1491  				"login": "l",
  1492  				"id": 1,
  1493  				"avatar_url": "a",
  1494  				"gravatar_id": "g",
  1495  				"name": "n",
  1496  				"company": "c",
  1497  				"blog": "b",
  1498  				"location": "l",
  1499  				"email": "e",
  1500  				"hireable": true,
  1501  				"bio": "b",
  1502  				"twitter_username": "t",
  1503  				"public_repos": 1,
  1504  				"followers": 1,
  1505  				"following": 1,
  1506  				"created_at": ` + referenceTimeStr + `,
  1507  				"suspended_at": ` + referenceTimeStr + `,
  1508  				"url": "u"
  1509  			}
  1510  		],
  1511  		"auto_merge": {
  1512  			"enabled_by": {
  1513  				"login": "l",
  1514  				"id": 1,
  1515  				"avatar_url": "a",
  1516  				"gravatar_id": "g",
  1517  				"name": "n",
  1518  				"company": "c",
  1519  				"blog": "b",
  1520  				"location": "l",
  1521  				"email": "e",
  1522  				"hireable": true,
  1523  				"bio": "b",
  1524  				"twitter_username": "t",
  1525  				"public_repos": 1,
  1526  				"followers": 1,
  1527  				"following": 1,
  1528  				"created_at": ` + referenceTimeStr + `,
  1529  				"suspended_at": ` + referenceTimeStr + `,
  1530  				"url": "u"
  1531  			},
  1532  			"merge_method": "mm",
  1533  			"commit_title": "ct",
  1534  			"commit_message": "cm"
  1535  		},
  1536  		"requested_teams": [
  1537  			{
  1538  				"id": 1
  1539  			}
  1540  		],
  1541  		"_links": {
  1542  			"self": {
  1543  				"href": "href"
  1544  			},
  1545  			"html": {
  1546  				"href": "href"
  1547  			},
  1548  			"issue": {
  1549  				"href": "href"
  1550  			},
  1551  			"comments": {
  1552  				"href": "href"
  1553  			},
  1554  			"review_comments": {
  1555  				"href": "href"
  1556  			},
  1557  			"review_comment": {
  1558  				"href": "href"
  1559  			},
  1560  			"commits": {
  1561  				"href": "href"
  1562  			},
  1563  			"statuses": {
  1564  				"href": "href"
  1565  			}
  1566  		},
  1567  		"head": {
  1568  			"ref": "r2",
  1569  			"repo": {
  1570  				"id": 2
  1571  			}
  1572  		},
  1573  		"base": {
  1574  			"ref": "r2",
  1575  			"repo": {
  1576  				"id": 2
  1577  			}
  1578  		},
  1579  		"active_lock_reason": "alr"
  1580  	}`
  1581  
  1582  	testJSONMarshal(t, u, want)
  1583  }
  1584  

View as plain text