github.com/google/go-github/v33@v33.0.0/github/checks_test.go (about)

     1  // Copyright 2018 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  	"fmt"
    11  	"net/http"
    12  	"reflect"
    13  	"testing"
    14  	"time"
    15  )
    16  
    17  func TestChecksService_GetCheckRun(t *testing.T) {
    18  	client, mux, _, teardown := setup()
    19  	defer teardown()
    20  
    21  	mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) {
    22  		testMethod(t, r, "GET")
    23  
    24  		fmt.Fprint(w, `{
    25  			"id": 1,
    26                          "name":"testCheckRun",
    27  			"status": "completed",
    28  			"conclusion": "neutral",
    29  			"started_at": "2018-05-04T01:14:52Z",
    30  			"completed_at": "2018-05-04T01:14:52Z"}`)
    31  	})
    32  	checkRun, _, err := client.Checks.GetCheckRun(context.Background(), "o", "r", 1)
    33  	if err != nil {
    34  		t.Errorf("Checks.GetCheckRun return error: %v", err)
    35  	}
    36  	startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
    37  	completeAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
    38  
    39  	want := &CheckRun{
    40  		ID:          Int64(1),
    41  		Status:      String("completed"),
    42  		Conclusion:  String("neutral"),
    43  		StartedAt:   &Timestamp{startedAt},
    44  		CompletedAt: &Timestamp{completeAt},
    45  		Name:        String("testCheckRun"),
    46  	}
    47  	if !reflect.DeepEqual(checkRun, want) {
    48  		t.Errorf("Checks.GetCheckRun return %+v, want %+v", checkRun, want)
    49  	}
    50  }
    51  
    52  func TestChecksService_GetCheckSuite(t *testing.T) {
    53  	client, mux, _, teardown := setup()
    54  	defer teardown()
    55  
    56  	mux.HandleFunc("/repos/o/r/check-suites/1", func(w http.ResponseWriter, r *http.Request) {
    57  		testMethod(t, r, "GET")
    58  
    59  		fmt.Fprint(w, `{
    60  			"id": 1,
    61                          "head_branch":"master",
    62  			"head_sha": "deadbeef",
    63  			"conclusion": "neutral",
    64                          "before": "deadbeefb",
    65                          "after": "deadbeefa",
    66  			"status": "completed"}`)
    67  	})
    68  	checkSuite, _, err := client.Checks.GetCheckSuite(context.Background(), "o", "r", 1)
    69  	if err != nil {
    70  		t.Errorf("Checks.GetCheckSuite return error: %v", err)
    71  	}
    72  	want := &CheckSuite{
    73  		ID:         Int64(1),
    74  		HeadBranch: String("master"),
    75  		HeadSHA:    String("deadbeef"),
    76  		AfterSHA:   String("deadbeefa"),
    77  		BeforeSHA:  String("deadbeefb"),
    78  		Status:     String("completed"),
    79  		Conclusion: String("neutral"),
    80  	}
    81  	if !reflect.DeepEqual(checkSuite, want) {
    82  		t.Errorf("Checks.GetCheckSuite return %+v, want %+v", checkSuite, want)
    83  	}
    84  }
    85  
    86  func TestChecksService_CreateCheckRun(t *testing.T) {
    87  	client, mux, _, teardown := setup()
    88  	defer teardown()
    89  
    90  	mux.HandleFunc("/repos/o/r/check-runs", func(w http.ResponseWriter, r *http.Request) {
    91  		testMethod(t, r, "POST")
    92  
    93  		fmt.Fprint(w, `{
    94  			"id": 1,
    95                          "name":"testCreateCheckRun",
    96                          "head_sha":"deadbeef",
    97  			"status": "in_progress",
    98  			"conclusion": null,
    99  			"started_at": "2018-05-04T01:14:52Z",
   100  			"completed_at": null,
   101                          "output":{"title": "Mighty test report", "summary":"", "text":""}}`)
   102  	})
   103  	startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
   104  	checkRunOpt := CreateCheckRunOptions{
   105  		Name:      "testCreateCheckRun",
   106  		HeadSHA:   "deadbeef",
   107  		Status:    String("in_progress"),
   108  		StartedAt: &Timestamp{startedAt},
   109  		Output: &CheckRunOutput{
   110  			Title:   String("Mighty test report"),
   111  			Summary: String(""),
   112  			Text:    String(""),
   113  		},
   114  	}
   115  
   116  	checkRun, _, err := client.Checks.CreateCheckRun(context.Background(), "o", "r", checkRunOpt)
   117  	if err != nil {
   118  		t.Errorf("Checks.CreateCheckRun return error: %v", err)
   119  	}
   120  
   121  	want := &CheckRun{
   122  		ID:        Int64(1),
   123  		Status:    String("in_progress"),
   124  		StartedAt: &Timestamp{startedAt},
   125  		HeadSHA:   String("deadbeef"),
   126  		Name:      String("testCreateCheckRun"),
   127  		Output: &CheckRunOutput{
   128  			Title:   String("Mighty test report"),
   129  			Summary: String(""),
   130  			Text:    String(""),
   131  		},
   132  	}
   133  	if !reflect.DeepEqual(checkRun, want) {
   134  		t.Errorf("Checks.CreateCheckRun return %+v, want %+v", checkRun, want)
   135  	}
   136  }
   137  
   138  func TestChecksService_ListCheckRunAnnotations(t *testing.T) {
   139  	client, mux, _, teardown := setup()
   140  	defer teardown()
   141  
   142  	mux.HandleFunc("/repos/o/r/check-runs/1/annotations", func(w http.ResponseWriter, r *http.Request) {
   143  		testMethod(t, r, "GET")
   144  
   145  		testFormValues(t, r, values{
   146  			"page": "1",
   147  		})
   148  		fmt.Fprint(w, `[{
   149  		                           "path": "README.md",
   150  		                           "start_line": 2,
   151  		                           "end_line": 2,
   152  		                           "start_column": 1,
   153  		                           "end_column": 5,									
   154  		                           "annotation_level": "warning",
   155  		                           "message": "Check your spelling for 'banaas'.",
   156                                             "title": "Spell check",
   157  		                           "raw_details": "Do you mean 'bananas' or 'banana'?"}]`,
   158  		)
   159  	})
   160  
   161  	checkRunAnnotations, _, err := client.Checks.ListCheckRunAnnotations(context.Background(), "o", "r", 1, &ListOptions{Page: 1})
   162  	if err != nil {
   163  		t.Errorf("Checks.ListCheckRunAnnotations return error: %v", err)
   164  	}
   165  
   166  	want := []*CheckRunAnnotation{{
   167  		Path:            String("README.md"),
   168  		StartLine:       Int(2),
   169  		EndLine:         Int(2),
   170  		StartColumn:     Int(1),
   171  		EndColumn:       Int(5),
   172  		AnnotationLevel: String("warning"),
   173  		Message:         String("Check your spelling for 'banaas'."),
   174  		Title:           String("Spell check"),
   175  		RawDetails:      String("Do you mean 'bananas' or 'banana'?"),
   176  	}}
   177  
   178  	if !reflect.DeepEqual(checkRunAnnotations, want) {
   179  		t.Errorf("Checks.ListCheckRunAnnotations returned %+v, want %+v", checkRunAnnotations, want)
   180  	}
   181  }
   182  
   183  func TestChecksService_UpdateCheckRun(t *testing.T) {
   184  	client, mux, _, teardown := setup()
   185  	defer teardown()
   186  
   187  	mux.HandleFunc("/repos/o/r/check-runs/1", func(w http.ResponseWriter, r *http.Request) {
   188  		testMethod(t, r, "PATCH")
   189  
   190  		fmt.Fprint(w, `{
   191  			"id": 1,
   192                          "name":"testUpdateCheckRun",
   193  			"status": "completed",            
   194  			"conclusion": "neutral",
   195  			"started_at": "2018-05-04T01:14:52Z",
   196  			"completed_at": "2018-05-04T01:14:52Z",
   197                          "output":{"title": "Mighty test report", "summary":"There are 0 failures, 2 warnings and 1 notice", "text":"You may have misspelled some words."}}`)
   198  	})
   199  	startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
   200  	updateCheckRunOpt := UpdateCheckRunOptions{
   201  		Name:        "testUpdateCheckRun",
   202  		Status:      String("completed"),
   203  		CompletedAt: &Timestamp{startedAt},
   204  		Output: &CheckRunOutput{
   205  			Title:   String("Mighty test report"),
   206  			Summary: String("There are 0 failures, 2 warnings and 1 notice"),
   207  			Text:    String("You may have misspelled some words."),
   208  		},
   209  	}
   210  
   211  	checkRun, _, err := client.Checks.UpdateCheckRun(context.Background(), "o", "r", 1, updateCheckRunOpt)
   212  	if err != nil {
   213  		t.Errorf("Checks.UpdateCheckRun return error: %v", err)
   214  	}
   215  
   216  	want := &CheckRun{
   217  		ID:          Int64(1),
   218  		Status:      String("completed"),
   219  		StartedAt:   &Timestamp{startedAt},
   220  		CompletedAt: &Timestamp{startedAt},
   221  		Conclusion:  String("neutral"),
   222  		Name:        String("testUpdateCheckRun"),
   223  		Output: &CheckRunOutput{
   224  			Title:   String("Mighty test report"),
   225  			Summary: String("There are 0 failures, 2 warnings and 1 notice"),
   226  			Text:    String("You may have misspelled some words."),
   227  		},
   228  	}
   229  	if !reflect.DeepEqual(checkRun, want) {
   230  		t.Errorf("Checks.UpdateCheckRun return %+v, want %+v", checkRun, want)
   231  	}
   232  }
   233  
   234  func TestChecksService_ListCheckRunsForRef(t *testing.T) {
   235  	client, mux, _, teardown := setup()
   236  	defer teardown()
   237  
   238  	mux.HandleFunc("/repos/o/r/commits/master/check-runs", func(w http.ResponseWriter, r *http.Request) {
   239  		testMethod(t, r, "GET")
   240  
   241  		testFormValues(t, r, values{
   242  			"check_name": "testing",
   243  			"page":       "1",
   244  			"status":     "completed",
   245  			"filter":     "all",
   246  		})
   247  		fmt.Fprint(w, `{"total_count":1,
   248                                  "check_runs": [{
   249                                      "id": 1,
   250                                      "head_sha": "deadbeef",
   251                                      "status": "completed",
   252                                      "conclusion": "neutral",
   253                                      "started_at": "2018-05-04T01:14:52Z",
   254                                      "completed_at": "2018-05-04T01:14:52Z"}]}`,
   255  		)
   256  	})
   257  
   258  	opt := &ListCheckRunsOptions{
   259  		CheckName:   String("testing"),
   260  		Status:      String("completed"),
   261  		Filter:      String("all"),
   262  		ListOptions: ListOptions{Page: 1},
   263  	}
   264  	checkRuns, _, err := client.Checks.ListCheckRunsForRef(context.Background(), "o", "r", "master", opt)
   265  	if err != nil {
   266  		t.Errorf("Checks.ListCheckRunsForRef return error: %v", err)
   267  	}
   268  	startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
   269  	want := &ListCheckRunsResults{
   270  		Total: Int(1),
   271  		CheckRuns: []*CheckRun{{
   272  			ID:          Int64(1),
   273  			Status:      String("completed"),
   274  			StartedAt:   &Timestamp{startedAt},
   275  			CompletedAt: &Timestamp{startedAt},
   276  			Conclusion:  String("neutral"),
   277  			HeadSHA:     String("deadbeef"),
   278  		}},
   279  	}
   280  
   281  	if !reflect.DeepEqual(checkRuns, want) {
   282  		t.Errorf("Checks.ListCheckRunsForRef returned %+v, want %+v", checkRuns, want)
   283  	}
   284  }
   285  
   286  func TestChecksService_ListCheckRunsCheckSuite(t *testing.T) {
   287  	client, mux, _, teardown := setup()
   288  	defer teardown()
   289  
   290  	mux.HandleFunc("/repos/o/r/check-suites/1/check-runs", func(w http.ResponseWriter, r *http.Request) {
   291  		testMethod(t, r, "GET")
   292  
   293  		testFormValues(t, r, values{
   294  			"check_name": "testing",
   295  			"page":       "1",
   296  			"status":     "completed",
   297  			"filter":     "all",
   298  		})
   299  		fmt.Fprint(w, `{"total_count":1,
   300                                  "check_runs": [{
   301                                      "id": 1,
   302                                      "head_sha": "deadbeef",
   303                                      "status": "completed",
   304                                      "conclusion": "neutral",
   305                                      "started_at": "2018-05-04T01:14:52Z",
   306                                      "completed_at": "2018-05-04T01:14:52Z"}]}`,
   307  		)
   308  	})
   309  
   310  	opt := &ListCheckRunsOptions{
   311  		CheckName:   String("testing"),
   312  		Status:      String("completed"),
   313  		Filter:      String("all"),
   314  		ListOptions: ListOptions{Page: 1},
   315  	}
   316  	checkRuns, _, err := client.Checks.ListCheckRunsCheckSuite(context.Background(), "o", "r", 1, opt)
   317  	if err != nil {
   318  		t.Errorf("Checks.ListCheckRunsCheckSuite return error: %v", err)
   319  	}
   320  	startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
   321  	want := &ListCheckRunsResults{
   322  		Total: Int(1),
   323  		CheckRuns: []*CheckRun{{
   324  			ID:          Int64(1),
   325  			Status:      String("completed"),
   326  			StartedAt:   &Timestamp{startedAt},
   327  			CompletedAt: &Timestamp{startedAt},
   328  			Conclusion:  String("neutral"),
   329  			HeadSHA:     String("deadbeef"),
   330  		}},
   331  	}
   332  
   333  	if !reflect.DeepEqual(checkRuns, want) {
   334  		t.Errorf("Checks.ListCheckRunsCheckSuite returned %+v, want %+v", checkRuns, want)
   335  	}
   336  }
   337  
   338  func TestChecksService_ListCheckSuiteForRef(t *testing.T) {
   339  	client, mux, _, teardown := setup()
   340  	defer teardown()
   341  
   342  	mux.HandleFunc("/repos/o/r/commits/master/check-suites", func(w http.ResponseWriter, r *http.Request) {
   343  		testMethod(t, r, "GET")
   344  
   345  		testFormValues(t, r, values{
   346  			"check_name": "testing",
   347  			"page":       "1",
   348  			"app_id":     "2",
   349  		})
   350  		fmt.Fprint(w, `{"total_count":1,
   351                                  "check_suites": [{
   352                                      "id": 1,
   353                                      "head_sha": "deadbeef",
   354                                      "head_branch": "master",
   355                                      "status": "completed",
   356                                      "conclusion": "neutral",
   357                                      "before": "deadbeefb",
   358                                      "after": "deadbeefa"}]}`,
   359  		)
   360  	})
   361  
   362  	opt := &ListCheckSuiteOptions{
   363  		CheckName:   String("testing"),
   364  		AppID:       Int(2),
   365  		ListOptions: ListOptions{Page: 1},
   366  	}
   367  	checkSuites, _, err := client.Checks.ListCheckSuitesForRef(context.Background(), "o", "r", "master", opt)
   368  	if err != nil {
   369  		t.Errorf("Checks.ListCheckSuitesForRef return error: %v", err)
   370  	}
   371  	want := &ListCheckSuiteResults{
   372  		Total: Int(1),
   373  		CheckSuites: []*CheckSuite{{
   374  			ID:         Int64(1),
   375  			Status:     String("completed"),
   376  			Conclusion: String("neutral"),
   377  			HeadSHA:    String("deadbeef"),
   378  			HeadBranch: String("master"),
   379  			BeforeSHA:  String("deadbeefb"),
   380  			AfterSHA:   String("deadbeefa"),
   381  		}},
   382  	}
   383  
   384  	if !reflect.DeepEqual(checkSuites, want) {
   385  		t.Errorf("Checks.ListCheckSuitesForRef returned %+v, want %+v", checkSuites, want)
   386  	}
   387  }
   388  
   389  func TestChecksService_SetCheckSuitePreferences(t *testing.T) {
   390  	client, mux, _, teardown := setup()
   391  	defer teardown()
   392  
   393  	mux.HandleFunc("/repos/o/r/check-suites/preferences", func(w http.ResponseWriter, r *http.Request) {
   394  		testMethod(t, r, "PATCH")
   395  
   396  		testBody(t, r, `{"auto_trigger_checks":[{"app_id":2,"setting":false}]}`+"\n")
   397  		fmt.Fprint(w, `{"preferences":{"auto_trigger_checks":[{"app_id": 2,"setting": false}]}}`)
   398  	})
   399  	a := []*AutoTriggerCheck{{
   400  		AppID:   Int64(2),
   401  		Setting: Bool(false),
   402  	}}
   403  	opt := CheckSuitePreferenceOptions{AutoTriggerChecks: a}
   404  	prefResults, _, err := client.Checks.SetCheckSuitePreferences(context.Background(), "o", "r", opt)
   405  	if err != nil {
   406  		t.Errorf("Checks.SetCheckSuitePreferences return error: %v", err)
   407  	}
   408  
   409  	p := &PreferenceList{
   410  		AutoTriggerChecks: a,
   411  	}
   412  	want := &CheckSuitePreferenceResults{
   413  		Preferences: p,
   414  	}
   415  
   416  	if !reflect.DeepEqual(prefResults, want) {
   417  		t.Errorf("Checks.SetCheckSuitePreferences return %+v, want %+v", prefResults, want)
   418  	}
   419  }
   420  
   421  func TestChecksService_CreateCheckSuite(t *testing.T) {
   422  	client, mux, _, teardown := setup()
   423  	defer teardown()
   424  
   425  	mux.HandleFunc("/repos/o/r/check-suites", func(w http.ResponseWriter, r *http.Request) {
   426  		testMethod(t, r, "POST")
   427  
   428  		fmt.Fprint(w, `{
   429  			"id": 2,
   430                          "head_branch":"master",
   431                          "head_sha":"deadbeef",
   432  			"status": "completed",
   433  			"conclusion": "neutral",
   434                          "before": "deadbeefb",
   435                          "after": "deadbeefa"}`)
   436  	})
   437  
   438  	checkSuiteOpt := CreateCheckSuiteOptions{
   439  		HeadSHA:    "deadbeef",
   440  		HeadBranch: String("master"),
   441  	}
   442  
   443  	checkSuite, _, err := client.Checks.CreateCheckSuite(context.Background(), "o", "r", checkSuiteOpt)
   444  	if err != nil {
   445  		t.Errorf("Checks.CreateCheckSuite return error: %v", err)
   446  	}
   447  
   448  	want := &CheckSuite{
   449  		ID:         Int64(2),
   450  		Status:     String("completed"),
   451  		HeadSHA:    String("deadbeef"),
   452  		HeadBranch: String("master"),
   453  		Conclusion: String("neutral"),
   454  		BeforeSHA:  String("deadbeefb"),
   455  		AfterSHA:   String("deadbeefa"),
   456  	}
   457  	if !reflect.DeepEqual(checkSuite, want) {
   458  		t.Errorf("Checks.CreateCheckSuite return %+v, want %+v", checkSuite, want)
   459  	}
   460  }
   461  
   462  func TestChecksService_ReRequestCheckSuite(t *testing.T) {
   463  	client, mux, _, teardown := setup()
   464  	defer teardown()
   465  
   466  	mux.HandleFunc("/repos/o/r/check-suites/1/rerequest", func(w http.ResponseWriter, r *http.Request) {
   467  		testMethod(t, r, "POST")
   468  
   469  		w.WriteHeader(http.StatusCreated)
   470  	})
   471  	resp, err := client.Checks.ReRequestCheckSuite(context.Background(), "o", "r", 1)
   472  	if err != nil {
   473  		t.Errorf("Checks.ReRequestCheckSuite return error: %v", err)
   474  	}
   475  	if got, want := resp.StatusCode, http.StatusCreated; got != want {
   476  		t.Errorf("Checks.ReRequestCheckSuite = %v, want %v", got, want)
   477  	}
   478  }
   479  
   480  func Test_CheckRunMarshal(t *testing.T) {
   481  	testJSONMarshal(t, &CheckRun{}, "{}")
   482  
   483  	now := time.Now()
   484  	ts := now.Format(time.RFC3339Nano)
   485  
   486  	c := CheckRun{
   487  		ID:          Int64(1),
   488  		NodeID:      String("n"),
   489  		HeadSHA:     String("h"),
   490  		ExternalID:  String("1"),
   491  		URL:         String("u"),
   492  		HTMLURL:     String("u"),
   493  		DetailsURL:  String("u"),
   494  		Status:      String("s"),
   495  		Conclusion:  String("c"),
   496  		StartedAt:   &Timestamp{Time: now},
   497  		CompletedAt: &Timestamp{Time: now},
   498  		Output: &CheckRunOutput{
   499  			Annotations: []*CheckRunAnnotation{
   500  				{
   501  					AnnotationLevel: String("a"),
   502  					EndLine:         Int(1),
   503  					Message:         String("m"),
   504  					Path:            String("p"),
   505  					RawDetails:      String("r"),
   506  					StartLine:       Int(1),
   507  					Title:           String("t"),
   508  				},
   509  			},
   510  			AnnotationsCount: Int(1),
   511  			AnnotationsURL:   String("a"),
   512  			Images: []*CheckRunImage{
   513  				{
   514  					Alt:      String("a"),
   515  					ImageURL: String("i"),
   516  					Caption:  String("c"),
   517  				},
   518  			},
   519  			Title:   String("t"),
   520  			Summary: String("s"),
   521  			Text:    String("t"),
   522  		},
   523  		Name: String("n"),
   524  		CheckSuite: &CheckSuite{
   525  			ID: Int64(1),
   526  		},
   527  		App: &App{
   528  			ID:     Int64(1),
   529  			NodeID: String("n"),
   530  			Owner: &User{
   531  				Login:     String("l"),
   532  				ID:        Int64(1),
   533  				NodeID:    String("n"),
   534  				URL:       String("u"),
   535  				ReposURL:  String("r"),
   536  				EventsURL: String("e"),
   537  				AvatarURL: String("a"),
   538  			},
   539  			Name:        String("n"),
   540  			Description: String("d"),
   541  			HTMLURL:     String("h"),
   542  			ExternalURL: String("u"),
   543  			CreatedAt:   &Timestamp{now},
   544  			UpdatedAt:   &Timestamp{now},
   545  		},
   546  		PullRequests: []*PullRequest{
   547  			{
   548  				URL:    String("u"),
   549  				ID:     Int64(1),
   550  				Number: Int(1),
   551  				Head: &PullRequestBranch{
   552  					Ref: String("r"),
   553  					SHA: String("s"),
   554  					Repo: &Repository{
   555  						ID:   Int64(1),
   556  						URL:  String("s"),
   557  						Name: String("n"),
   558  					},
   559  				},
   560  				Base: &PullRequestBranch{
   561  					Ref: String("r"),
   562  					SHA: String("s"),
   563  					Repo: &Repository{
   564  						ID:   Int64(1),
   565  						URL:  String("u"),
   566  						Name: String("n"),
   567  					},
   568  				},
   569  			},
   570  		},
   571  	}
   572  	w := fmt.Sprintf(`{
   573  		"id": 1,
   574  		"node_id": "n",
   575  		"head_sha": "h",
   576  		"external_id": "1",
   577  		"url": "u",
   578  		"html_url": "u",
   579  		"details_url": "u",
   580  		"status": "s",
   581  		"conclusion": "c",
   582  		"started_at": "%s",
   583  		"completed_at": "%s",
   584  		"output": {
   585  			"title": "t",
   586  			"summary": "s",
   587  			"text": "t",
   588  			"annotations_count": 1,
   589  			"annotations_url": "a",
   590  			"annotations": [
   591  				{
   592  					"path": "p",
   593  					"start_line": 1,
   594  					"end_line": 1,
   595  					"annotation_level": "a",
   596  					"message": "m",
   597  					"title": "t",
   598  					"raw_details": "r"
   599  				}
   600  			],
   601  			"images": [
   602  				{
   603  					"alt": "a",
   604  					"image_url": "i",
   605  					"caption": "c"
   606  				}
   607  			]
   608  		},
   609  		"name": "n",
   610  		"check_suite": {
   611  			"id": 1
   612  		},
   613  		"app": {
   614  			"id": 1,
   615  			"node_id": "n",
   616  			"owner": {
   617  				"login": "l",
   618  				"id": 1,
   619  				"node_id": "n",
   620  				"avatar_url": "a",
   621  				"url": "u",
   622  				"events_url": "e",
   623  				"repos_url": "r"
   624  			},
   625  			"name": "n",
   626  			"description": "d",
   627  			"external_url": "u",
   628  			"html_url": "h",
   629  			"created_at": "%s",
   630  			"updated_at": "%s"
   631  		},
   632  		"pull_requests": [
   633  			{
   634  				"id": 1,
   635  				"number": 1,
   636  				"url": "u",
   637  				"head": {
   638  					"ref": "r",
   639  					"sha": "s",
   640  					"repo": {
   641  						"id": 1,
   642  						"name": "n",
   643  						"url": "s"
   644  					}
   645  				},
   646  				"base": {
   647  					"ref": "r",
   648  					"sha": "s",
   649  					"repo": {
   650  						"id": 1,
   651  						"name": "n",
   652  						"url": "u"
   653  					}
   654  				}
   655  			}
   656  		]
   657  	  }`, ts, ts, ts, ts)
   658  
   659  	testJSONMarshal(t, &c, w)
   660  }
   661  
   662  func Test_CheckSuiteMarshal(t *testing.T) {
   663  	testJSONMarshal(t, &CheckSuite{}, "{}")
   664  
   665  	now := time.Now()
   666  	ts := now.Format(time.RFC3339Nano)
   667  
   668  	c := CheckSuite{
   669  		ID:         Int64(1),
   670  		NodeID:     String("n"),
   671  		HeadBranch: String("h"),
   672  		HeadSHA:    String("h"),
   673  		URL:        String("u"),
   674  		BeforeSHA:  String("b"),
   675  		AfterSHA:   String("a"),
   676  		Status:     String("s"),
   677  		Conclusion: String("c"),
   678  		App: &App{
   679  			ID:     Int64(1),
   680  			NodeID: String("n"),
   681  			Owner: &User{
   682  				Login:     String("l"),
   683  				ID:        Int64(1),
   684  				NodeID:    String("n"),
   685  				URL:       String("u"),
   686  				ReposURL:  String("r"),
   687  				EventsURL: String("e"),
   688  				AvatarURL: String("a"),
   689  			},
   690  			Name:        String("n"),
   691  			Description: String("d"),
   692  			HTMLURL:     String("h"),
   693  			ExternalURL: String("u"),
   694  			CreatedAt:   &Timestamp{now},
   695  			UpdatedAt:   &Timestamp{now},
   696  		},
   697  		Repository: &Repository{
   698  			ID: Int64(1),
   699  		},
   700  		PullRequests: []*PullRequest{
   701  			{
   702  				URL:    String("u"),
   703  				ID:     Int64(1),
   704  				Number: Int(1),
   705  				Head: &PullRequestBranch{
   706  					Ref: String("r"),
   707  					SHA: String("s"),
   708  					Repo: &Repository{
   709  						ID:   Int64(1),
   710  						URL:  String("s"),
   711  						Name: String("n"),
   712  					},
   713  				},
   714  				Base: &PullRequestBranch{
   715  					Ref: String("r"),
   716  					SHA: String("s"),
   717  					Repo: &Repository{
   718  						ID:   Int64(1),
   719  						URL:  String("u"),
   720  						Name: String("n"),
   721  					},
   722  				},
   723  			},
   724  		},
   725  		HeadCommit: &Commit{
   726  			SHA: String("s"),
   727  		},
   728  	}
   729  
   730  	w := fmt.Sprintf(`{
   731  			"id": 1,
   732  			"node_id": "n",
   733  			"head_branch": "h",
   734  			"head_sha": "h",
   735  			"url": "u",
   736  			"before": "b",
   737  			"after": "a",
   738  			"status": "s",
   739  			"conclusion": "c",
   740  			"app": {
   741  				"id": 1,
   742  				"node_id": "n",
   743  				"owner": {
   744  					"login": "l",
   745  					"id": 1,
   746  					"node_id": "n",
   747  					"avatar_url": "a",
   748  					"url": "u",
   749  					"events_url": "e",
   750  					"repos_url": "r"
   751  				},
   752  				"name": "n",
   753  				"description": "d",
   754  				"external_url": "u",
   755  				"html_url": "h",
   756  				"created_at": "%s",
   757  				"updated_at": "%s"
   758  			},
   759  			"repository": {
   760  				"id": 1
   761  			},
   762  			"pull_requests": [
   763  			{
   764  				"id": 1,
   765  				"number": 1,
   766  				"url": "u",
   767  				"head": {
   768  					"ref": "r",
   769  					"sha": "s",
   770  					"repo": {
   771  						"id": 1,
   772  						"name": "n",
   773  						"url": "s"
   774  					}
   775  				},
   776  				"base": {
   777  					"ref": "r",
   778  					"sha": "s",
   779  					"repo": {
   780  						"id": 1,
   781  						"name": "n",
   782  						"url": "u"
   783  					}
   784  				}
   785  			}
   786  		],
   787  		"head_commit": {
   788  			"sha": "s"
   789  		}
   790  		}`, ts, ts)
   791  
   792  	testJSONMarshal(t, &c, w)
   793  }