github.com/google/go-github/v57@v57.0.0/github/actions_workflow_runs_test.go (about)

     1  // Copyright 2020 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  	"net/http"
    13  	"net/url"
    14  	"testing"
    15  	"time"
    16  
    17  	"github.com/google/go-cmp/cmp"
    18  )
    19  
    20  func TestActionsService_ListWorkflowRunsByID(t *testing.T) {
    21  	client, mux, _, teardown := setup()
    22  	defer teardown()
    23  
    24  	mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) {
    25  		testMethod(t, r, "GET")
    26  		testFormValues(t, r, values{"per_page": "2", "page": "2"})
    27  		fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`)
    28  	})
    29  
    30  	opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
    31  	ctx := context.Background()
    32  	runs, _, err := client.Actions.ListWorkflowRunsByID(ctx, "o", "r", 29679449, opts)
    33  	if err != nil {
    34  		t.Errorf("Actions.ListWorkFlowRunsByID returned error: %v", err)
    35  	}
    36  
    37  	want := &WorkflowRuns{
    38  		TotalCount: Int(4),
    39  		WorkflowRuns: []*WorkflowRun{
    40  			{ID: Int64(399444496), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
    41  			{ID: Int64(399444497), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
    42  		},
    43  	}
    44  	if !cmp.Equal(runs, want) {
    45  		t.Errorf("Actions.ListWorkflowRunsByID returned %+v, want %+v", runs, want)
    46  	}
    47  
    48  	const methodName = "ListWorkflowRunsByID"
    49  	testBadOptions(t, methodName, func() (err error) {
    50  		_, _, err = client.Actions.ListWorkflowRunsByID(ctx, "\n", "\n", 29679449, opts)
    51  		return err
    52  	})
    53  
    54  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    55  		got, resp, err := client.Actions.ListWorkflowRunsByID(ctx, "o", "r", 29679449, opts)
    56  		if got != nil {
    57  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    58  		}
    59  		return resp, err
    60  	})
    61  }
    62  
    63  func TestActionsService_ListWorkflowRunsFileName(t *testing.T) {
    64  	client, mux, _, teardown := setup()
    65  	defer teardown()
    66  
    67  	mux.HandleFunc("/repos/o/r/actions/workflows/29679449/runs", func(w http.ResponseWriter, r *http.Request) {
    68  		testMethod(t, r, "GET")
    69  		testFormValues(t, r, values{"per_page": "2", "page": "2"})
    70  		fmt.Fprint(w, `{"total_count":4,"workflow_runs":[{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"},{"id":399444497,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}]}`)
    71  	})
    72  
    73  	opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
    74  	ctx := context.Background()
    75  	runs, _, err := client.Actions.ListWorkflowRunsByFileName(ctx, "o", "r", "29679449", opts)
    76  	if err != nil {
    77  		t.Errorf("Actions.ListWorkFlowRunsByFileName returned error: %v", err)
    78  	}
    79  
    80  	want := &WorkflowRuns{
    81  		TotalCount: Int(4),
    82  		WorkflowRuns: []*WorkflowRun{
    83  			{ID: Int64(399444496), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
    84  			{ID: Int64(399444497), RunNumber: Int(296), CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)}},
    85  		},
    86  	}
    87  	if !cmp.Equal(runs, want) {
    88  		t.Errorf("Actions.ListWorkflowRunsByFileName returned %+v, want %+v", runs, want)
    89  	}
    90  
    91  	const methodName = "ListWorkflowRunsByFileName"
    92  	testBadOptions(t, methodName, func() (err error) {
    93  		_, _, err = client.Actions.ListWorkflowRunsByFileName(ctx, "\n", "\n", "29679449", opts)
    94  		return err
    95  	})
    96  
    97  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    98  		got, resp, err := client.Actions.ListWorkflowRunsByFileName(ctx, "o", "r", "29679449", opts)
    99  		if got != nil {
   100  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   101  		}
   102  		return resp, err
   103  	})
   104  }
   105  
   106  func TestActionsService_GetWorkflowRunByID(t *testing.T) {
   107  	client, mux, _, teardown := setup()
   108  	defer teardown()
   109  
   110  	mux.HandleFunc("/repos/o/r/actions/runs/29679449", func(w http.ResponseWriter, r *http.Request) {
   111  		testMethod(t, r, "GET")
   112  		fmt.Fprint(w, `{"id":399444496,"run_number":296,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}}`)
   113  	})
   114  
   115  	ctx := context.Background()
   116  	runs, _, err := client.Actions.GetWorkflowRunByID(ctx, "o", "r", 29679449)
   117  	if err != nil {
   118  		t.Errorf("Actions.GetWorkflowRunByID returned error: %v", err)
   119  	}
   120  
   121  	want := &WorkflowRun{
   122  		ID:        Int64(399444496),
   123  		RunNumber: Int(296),
   124  		CreatedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
   125  		UpdatedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
   126  	}
   127  
   128  	if !cmp.Equal(runs, want) {
   129  		t.Errorf("Actions.GetWorkflowRunByID returned %+v, want %+v", runs, want)
   130  	}
   131  
   132  	const methodName = "GetWorkflowRunByID"
   133  	testBadOptions(t, methodName, func() (err error) {
   134  		_, _, err = client.Actions.GetWorkflowRunByID(ctx, "\n", "\n", 29679449)
   135  		return err
   136  	})
   137  
   138  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   139  		got, resp, err := client.Actions.GetWorkflowRunByID(ctx, "o", "r", 29679449)
   140  		if got != nil {
   141  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   142  		}
   143  		return resp, err
   144  	})
   145  }
   146  
   147  func TestActionsService_GetWorkflowRunAttempt(t *testing.T) {
   148  	client, mux, _, teardown := setup()
   149  	defer teardown()
   150  
   151  	mux.HandleFunc("/repos/o/r/actions/runs/29679449/attempts/3", func(w http.ResponseWriter, r *http.Request) {
   152  		testMethod(t, r, "GET")
   153  		testFormValues(t, r, values{"exclude_pull_requests": "true"})
   154  		fmt.Fprint(w, `{"id":399444496,"run_number":296,"run_attempt":3,"created_at":"2019-01-02T15:04:05Z","updated_at":"2020-01-02T15:04:05Z"}}`)
   155  	})
   156  
   157  	opts := &WorkflowRunAttemptOptions{ExcludePullRequests: Bool(true)}
   158  	ctx := context.Background()
   159  	runs, _, err := client.Actions.GetWorkflowRunAttempt(ctx, "o", "r", 29679449, 3, opts)
   160  	if err != nil {
   161  		t.Errorf("Actions.GetWorkflowRunAttempt returned error: %v", err)
   162  	}
   163  
   164  	want := &WorkflowRun{
   165  		ID:         Int64(399444496),
   166  		RunNumber:  Int(296),
   167  		RunAttempt: Int(3),
   168  		CreatedAt:  &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
   169  		UpdatedAt:  &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
   170  	}
   171  
   172  	if !cmp.Equal(runs, want) {
   173  		t.Errorf("Actions.GetWorkflowRunAttempt returned %+v, want %+v", runs, want)
   174  	}
   175  
   176  	const methodName = "GetWorkflowRunAttempt"
   177  	testBadOptions(t, methodName, func() (err error) {
   178  		_, _, err = client.Actions.GetWorkflowRunAttempt(ctx, "\n", "\n", 29679449, 3, opts)
   179  		return err
   180  	})
   181  
   182  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   183  		got, resp, err := client.Actions.GetWorkflowRunAttempt(ctx, "o", "r", 29679449, 3, opts)
   184  		if got != nil {
   185  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   186  		}
   187  		return resp, err
   188  	})
   189  }
   190  
   191  func TestActionsService_GetWorkflowRunAttemptLogs(t *testing.T) {
   192  	client, mux, _, teardown := setup()
   193  	defer teardown()
   194  
   195  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/attempts/2/logs", func(w http.ResponseWriter, r *http.Request) {
   196  		testMethod(t, r, "GET")
   197  		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
   198  	})
   199  
   200  	ctx := context.Background()
   201  	url, resp, err := client.Actions.GetWorkflowRunAttemptLogs(ctx, "o", "r", 399444496, 2, 1)
   202  	if err != nil {
   203  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned error: %v", err)
   204  	}
   205  	if resp.StatusCode != http.StatusFound {
   206  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
   207  	}
   208  	want := "http://github.com/a"
   209  	if url.String() != want {
   210  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned %+v, want %+v", url.String(), want)
   211  	}
   212  
   213  	const methodName = "GetWorkflowRunAttemptLogs"
   214  	testBadOptions(t, methodName, func() (err error) {
   215  		_, _, err = client.Actions.GetWorkflowRunAttemptLogs(ctx, "\n", "\n", 399444496, 2, 1)
   216  		return err
   217  	})
   218  }
   219  
   220  func TestActionsService_GetWorkflowRunAttemptLogs_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {
   221  	client, mux, _, teardown := setup()
   222  	defer teardown()
   223  
   224  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/attempts/2/logs", func(w http.ResponseWriter, r *http.Request) {
   225  		testMethod(t, r, "GET")
   226  		http.Redirect(w, r, "http://github.com/a", http.StatusMovedPermanently)
   227  	})
   228  
   229  	ctx := context.Background()
   230  	_, resp, _ := client.Actions.GetWorkflowRunAttemptLogs(ctx, "o", "r", 399444496, 2, 0)
   231  	if resp.StatusCode != http.StatusMovedPermanently {
   232  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned status: %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
   233  	}
   234  }
   235  
   236  func TestActionsService_GetWorkflowRunAttemptLogs_StatusMovedPermanently_followRedirects(t *testing.T) {
   237  	client, mux, serverURL, teardown := setup()
   238  	defer teardown()
   239  
   240  	// Mock a redirect link, which leads to an archive link
   241  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/attempts/2/logs", func(w http.ResponseWriter, r *http.Request) {
   242  		testMethod(t, r, "GET")
   243  		redirectURL, _ := url.Parse(serverURL + baseURLPath + "/redirect")
   244  		http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
   245  	})
   246  
   247  	mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
   248  		testMethod(t, r, "GET")
   249  		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
   250  	})
   251  
   252  	ctx := context.Background()
   253  	url, resp, err := client.Actions.GetWorkflowRunAttemptLogs(ctx, "o", "r", 399444496, 2, 1)
   254  	if err != nil {
   255  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned error: %v", err)
   256  	}
   257  
   258  	if resp.StatusCode != http.StatusFound {
   259  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
   260  	}
   261  
   262  	want := "http://github.com/a"
   263  	if url.String() != want {
   264  		t.Errorf("Actions.GetWorkflowRunAttemptLogs returned %+v, want %+v", url.String(), want)
   265  	}
   266  
   267  	const methodName = "GetWorkflowRunAttemptLogs"
   268  	testBadOptions(t, methodName, func() (err error) {
   269  		_, _, err = client.Actions.GetWorkflowRunAttemptLogs(ctx, "\n", "\n", 399444496, 2, 1)
   270  		return err
   271  	})
   272  }
   273  
   274  func TestActionsService_RerunWorkflowRunByID(t *testing.T) {
   275  	client, mux, _, teardown := setup()
   276  	defer teardown()
   277  
   278  	mux.HandleFunc("/repos/o/r/actions/runs/3434/rerun", func(w http.ResponseWriter, r *http.Request) {
   279  		testMethod(t, r, "POST")
   280  		w.WriteHeader(http.StatusCreated)
   281  	})
   282  
   283  	ctx := context.Background()
   284  	resp, err := client.Actions.RerunWorkflowByID(ctx, "o", "r", 3434)
   285  	if err != nil {
   286  		t.Errorf("Actions.RerunWorkflowByID returned error: %v", err)
   287  	}
   288  	if resp.StatusCode != http.StatusCreated {
   289  		t.Errorf("Actions.RerunWorkflowRunByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
   290  	}
   291  
   292  	const methodName = "RerunWorkflowByID"
   293  	testBadOptions(t, methodName, func() (err error) {
   294  		_, err = client.Actions.RerunWorkflowByID(ctx, "\n", "\n", 3434)
   295  		return err
   296  	})
   297  
   298  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   299  		return client.Actions.RerunWorkflowByID(ctx, "o", "r", 3434)
   300  	})
   301  }
   302  
   303  func TestActionsService_RerunFailedJobsByID(t *testing.T) {
   304  	client, mux, _, teardown := setup()
   305  	defer teardown()
   306  
   307  	mux.HandleFunc("/repos/o/r/actions/runs/3434/rerun-failed-jobs", func(w http.ResponseWriter, r *http.Request) {
   308  		testMethod(t, r, "POST")
   309  		w.WriteHeader(http.StatusCreated)
   310  	})
   311  
   312  	ctx := context.Background()
   313  	resp, err := client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
   314  	if err != nil {
   315  		t.Errorf("Actions.RerunFailedJobsByID returned error: %v", err)
   316  	}
   317  	if resp.StatusCode != http.StatusCreated {
   318  		t.Errorf("Actions.RerunFailedJobsByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
   319  	}
   320  
   321  	const methodName = "RerunFailedJobsByID"
   322  	testBadOptions(t, methodName, func() (err error) {
   323  		_, err = client.Actions.RerunFailedJobsByID(ctx, "\n", "\n", 3434)
   324  		return err
   325  	})
   326  
   327  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   328  		return client.Actions.RerunFailedJobsByID(ctx, "o", "r", 3434)
   329  	})
   330  }
   331  
   332  func TestActionsService_RerunJobByID(t *testing.T) {
   333  	client, mux, _, teardown := setup()
   334  	defer teardown()
   335  
   336  	mux.HandleFunc("/repos/o/r/actions/jobs/3434/rerun", func(w http.ResponseWriter, r *http.Request) {
   337  		testMethod(t, r, "POST")
   338  		w.WriteHeader(http.StatusCreated)
   339  	})
   340  
   341  	ctx := context.Background()
   342  	resp, err := client.Actions.RerunJobByID(ctx, "o", "r", 3434)
   343  	if err != nil {
   344  		t.Errorf("Actions.RerunJobByID returned error: %v", err)
   345  	}
   346  	if resp.StatusCode != http.StatusCreated {
   347  		t.Errorf("Actions.RerunJobByID returned status: %d, want %d", resp.StatusCode, http.StatusCreated)
   348  	}
   349  
   350  	const methodName = "RerunJobByID"
   351  	testBadOptions(t, methodName, func() (err error) {
   352  		_, err = client.Actions.RerunJobByID(ctx, "\n", "\n", 3434)
   353  		return err
   354  	})
   355  
   356  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   357  		return client.Actions.RerunJobByID(ctx, "o", "r", 3434)
   358  	})
   359  }
   360  
   361  func TestActionsService_CancelWorkflowRunByID(t *testing.T) {
   362  	client, mux, _, teardown := setup()
   363  	defer teardown()
   364  
   365  	mux.HandleFunc("/repos/o/r/actions/runs/3434/cancel", func(w http.ResponseWriter, r *http.Request) {
   366  		testMethod(t, r, "POST")
   367  		w.WriteHeader(http.StatusAccepted)
   368  	})
   369  
   370  	ctx := context.Background()
   371  	resp, err := client.Actions.CancelWorkflowRunByID(ctx, "o", "r", 3434)
   372  	if _, ok := err.(*AcceptedError); !ok {
   373  		t.Errorf("Actions.CancelWorkflowRunByID returned error: %v (want AcceptedError)", err)
   374  	}
   375  	if resp.StatusCode != http.StatusAccepted {
   376  		t.Errorf("Actions.CancelWorkflowRunByID returned status: %d, want %d", resp.StatusCode, http.StatusAccepted)
   377  	}
   378  
   379  	const methodName = "CancelWorkflowRunByID"
   380  	testBadOptions(t, methodName, func() (err error) {
   381  		_, err = client.Actions.CancelWorkflowRunByID(ctx, "\n", "\n", 3434)
   382  		return err
   383  	})
   384  
   385  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   386  		return client.Actions.CancelWorkflowRunByID(ctx, "o", "r", 3434)
   387  	})
   388  }
   389  
   390  func TestActionsService_GetWorkflowRunLogs(t *testing.T) {
   391  	client, mux, _, teardown := setup()
   392  	defer teardown()
   393  
   394  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
   395  		testMethod(t, r, "GET")
   396  		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
   397  	})
   398  
   399  	ctx := context.Background()
   400  	url, resp, err := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, 1)
   401  	if err != nil {
   402  		t.Errorf("Actions.GetWorkflowRunLogs returned error: %v", err)
   403  	}
   404  	if resp.StatusCode != http.StatusFound {
   405  		t.Errorf("Actions.GetWorkflowRunLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
   406  	}
   407  	want := "http://github.com/a"
   408  	if url.String() != want {
   409  		t.Errorf("Actions.GetWorkflowRunLogs returned %+v, want %+v", url.String(), want)
   410  	}
   411  
   412  	const methodName = "GetWorkflowRunLogs"
   413  	testBadOptions(t, methodName, func() (err error) {
   414  		_, _, err = client.Actions.GetWorkflowRunLogs(ctx, "\n", "\n", 399444496, 1)
   415  		return err
   416  	})
   417  }
   418  
   419  func TestActionsService_GetWorkflowRunLogs_StatusMovedPermanently_dontFollowRedirects(t *testing.T) {
   420  	client, mux, _, teardown := setup()
   421  	defer teardown()
   422  
   423  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
   424  		testMethod(t, r, "GET")
   425  		http.Redirect(w, r, "http://github.com/a", http.StatusMovedPermanently)
   426  	})
   427  
   428  	ctx := context.Background()
   429  	_, resp, _ := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, 0)
   430  	if resp.StatusCode != http.StatusMovedPermanently {
   431  		t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
   432  	}
   433  }
   434  
   435  func TestActionsService_GetWorkflowRunLogs_StatusMovedPermanently_followRedirects(t *testing.T) {
   436  	client, mux, serverURL, teardown := setup()
   437  	defer teardown()
   438  
   439  	// Mock a redirect link, which leads to an archive link
   440  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
   441  		testMethod(t, r, "GET")
   442  		redirectURL, _ := url.Parse(serverURL + baseURLPath + "/redirect")
   443  		http.Redirect(w, r, redirectURL.String(), http.StatusMovedPermanently)
   444  	})
   445  
   446  	mux.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) {
   447  		testMethod(t, r, "GET")
   448  		http.Redirect(w, r, "http://github.com/a", http.StatusFound)
   449  	})
   450  
   451  	ctx := context.Background()
   452  	url, resp, err := client.Actions.GetWorkflowRunLogs(ctx, "o", "r", 399444496, 1)
   453  	if err != nil {
   454  		t.Errorf("Actions.GetWorkflowJobLogs returned error: %v", err)
   455  	}
   456  
   457  	if resp.StatusCode != http.StatusFound {
   458  		t.Errorf("Actions.GetWorkflowJobLogs returned status: %d, want %d", resp.StatusCode, http.StatusFound)
   459  	}
   460  
   461  	want := "http://github.com/a"
   462  	if url.String() != want {
   463  		t.Errorf("Actions.GetWorkflowJobLogs returned %+v, want %+v", url.String(), want)
   464  	}
   465  
   466  	const methodName = "GetWorkflowRunLogs"
   467  	testBadOptions(t, methodName, func() (err error) {
   468  		_, _, err = client.Actions.GetWorkflowRunLogs(ctx, "\n", "\n", 399444496, 1)
   469  		return err
   470  	})
   471  }
   472  
   473  func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) {
   474  	client, mux, _, teardown := setup()
   475  	defer teardown()
   476  
   477  	mux.HandleFunc("/repos/o/r/actions/runs", func(w http.ResponseWriter, r *http.Request) {
   478  		testMethod(t, r, "GET")
   479  		testFormValues(t, r, values{"per_page": "2", "page": "2"})
   480  		fmt.Fprint(w, `{"total_count":2,
   481  		"workflow_runs":[
   482  			{"id":298499444,"run_number":301,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"},
   483  			{"id":298499445,"run_number":302,"created_at":"2020-04-11T11:14:54Z","updated_at":"2020-04-11T11:14:54Z"}]}`)
   484  	})
   485  
   486  	opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
   487  	ctx := context.Background()
   488  	runs, _, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)
   489  	if err != nil {
   490  		t.Errorf("Actions.ListRepositoryWorkflowRuns returned error: %v", err)
   491  	}
   492  
   493  	expected := &WorkflowRuns{
   494  		TotalCount: Int(2),
   495  		WorkflowRuns: []*WorkflowRun{
   496  			{ID: Int64(298499444), RunNumber: Int(301), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}},
   497  			{ID: Int64(298499445), RunNumber: Int(302), CreatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}, UpdatedAt: &Timestamp{time.Date(2020, time.April, 11, 11, 14, 54, 0, time.UTC)}},
   498  		},
   499  	}
   500  
   501  	if !cmp.Equal(runs, expected) {
   502  		t.Errorf("Actions.ListRepositoryWorkflowRuns returned %+v, want %+v", runs, expected)
   503  	}
   504  
   505  	const methodName = "ListRepositoryWorkflowRuns"
   506  	testBadOptions(t, methodName, func() (err error) {
   507  		_, _, err = client.Actions.ListRepositoryWorkflowRuns(ctx, "\n", "\n", opts)
   508  
   509  		return err
   510  	})
   511  
   512  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   513  		got, resp, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)
   514  
   515  		if got != nil {
   516  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   517  		}
   518  		return resp, err
   519  	})
   520  }
   521  
   522  func TestActionService_DeleteWorkflowRun(t *testing.T) {
   523  	client, mux, _, teardown := setup()
   524  	defer teardown()
   525  
   526  	mux.HandleFunc("/repos/o/r/actions/runs/399444496", func(w http.ResponseWriter, r *http.Request) {
   527  		testMethod(t, r, "DELETE")
   528  
   529  		w.WriteHeader(http.StatusNoContent)
   530  	})
   531  
   532  	ctx := context.Background()
   533  	if _, err := client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496); err != nil {
   534  		t.Errorf("DeleteWorkflowRun returned error: %v", err)
   535  	}
   536  
   537  	const methodName = "DeleteWorkflowRun"
   538  	testBadOptions(t, methodName, func() (err error) {
   539  		_, err = client.Actions.DeleteWorkflowRun(ctx, "\n", "\n", 399444496)
   540  		return err
   541  	})
   542  
   543  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   544  		return client.Actions.DeleteWorkflowRun(ctx, "o", "r", 399444496)
   545  	})
   546  }
   547  
   548  func TestActionService_DeleteWorkflowRunLogs(t *testing.T) {
   549  	client, mux, _, teardown := setup()
   550  	defer teardown()
   551  
   552  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/logs", func(w http.ResponseWriter, r *http.Request) {
   553  		testMethod(t, r, "DELETE")
   554  
   555  		w.WriteHeader(http.StatusNoContent)
   556  	})
   557  
   558  	ctx := context.Background()
   559  	if _, err := client.Actions.DeleteWorkflowRunLogs(ctx, "o", "r", 399444496); err != nil {
   560  		t.Errorf("DeleteWorkflowRunLogs returned error: %v", err)
   561  	}
   562  
   563  	const methodName = "DeleteWorkflowRunLogs"
   564  	testBadOptions(t, methodName, func() (err error) {
   565  		_, err = client.Actions.DeleteWorkflowRunLogs(ctx, "\n", "\n", 399444496)
   566  		return err
   567  	})
   568  
   569  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   570  		return client.Actions.DeleteWorkflowRunLogs(ctx, "o", "r", 399444496)
   571  	})
   572  }
   573  
   574  func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
   575  	client, mux, _, teardown := setup()
   576  	defer teardown()
   577  
   578  	mux.HandleFunc("/repos/o/r/actions/runs/29679449/timing", func(w http.ResponseWriter, r *http.Request) {
   579  		testMethod(t, r, "GET")
   580  		fmt.Fprint(w, `{"billable":{"UBUNTU":{"total_ms":180000,"jobs":1,"job_runs":[{"job_id":1,"duration_ms":60000}]},"MACOS":{"total_ms":240000,"jobs":2,"job_runs":[{"job_id":2,"duration_ms":30000},{"job_id":3,"duration_ms":10000}]},"WINDOWS":{"total_ms":300000,"jobs":2}},"run_duration_ms":500000}`)
   581  	})
   582  
   583  	ctx := context.Background()
   584  	workflowRunUsage, _, err := client.Actions.GetWorkflowRunUsageByID(ctx, "o", "r", 29679449)
   585  	if err != nil {
   586  		t.Errorf("Actions.GetWorkflowRunUsageByID returned error: %v", err)
   587  	}
   588  
   589  	want := &WorkflowRunUsage{
   590  		Billable: &WorkflowRunBillMap{
   591  			"UBUNTU": &WorkflowRunBill{
   592  				TotalMS: Int64(180000),
   593  				Jobs:    Int(1),
   594  				JobRuns: []*WorkflowRunJobRun{
   595  					{
   596  						JobID:      Int(1),
   597  						DurationMS: Int64(60000),
   598  					},
   599  				},
   600  			},
   601  			"MACOS": &WorkflowRunBill{
   602  				TotalMS: Int64(240000),
   603  				Jobs:    Int(2),
   604  				JobRuns: []*WorkflowRunJobRun{
   605  					{
   606  						JobID:      Int(2),
   607  						DurationMS: Int64(30000),
   608  					},
   609  					{
   610  						JobID:      Int(3),
   611  						DurationMS: Int64(10000),
   612  					},
   613  				},
   614  			},
   615  			"WINDOWS": &WorkflowRunBill{
   616  				TotalMS: Int64(300000),
   617  				Jobs:    Int(2),
   618  			},
   619  		},
   620  		RunDurationMS: Int64(500000),
   621  	}
   622  
   623  	if !cmp.Equal(workflowRunUsage, want) {
   624  		t.Errorf("Actions.GetWorkflowRunUsageByID returned %+v, want %+v", workflowRunUsage, want)
   625  	}
   626  
   627  	const methodName = "GetWorkflowRunUsageByID"
   628  	testBadOptions(t, methodName, func() (err error) {
   629  		_, _, err = client.Actions.GetWorkflowRunUsageByID(ctx, "\n", "\n", 29679449)
   630  		return err
   631  	})
   632  
   633  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   634  		got, resp, err := client.Actions.GetWorkflowRunUsageByID(ctx, "o", "r", 29679449)
   635  		if got != nil {
   636  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   637  		}
   638  		return resp, err
   639  	})
   640  }
   641  
   642  func TestWorkflowRun_Marshal(t *testing.T) {
   643  	testJSONMarshal(t, &WorkflowRun{}, "{}")
   644  
   645  	u := &WorkflowRun{
   646  		ID:         Int64(1),
   647  		Name:       String("n"),
   648  		NodeID:     String("nid"),
   649  		HeadBranch: String("hb"),
   650  		HeadSHA:    String("hs"),
   651  		RunNumber:  Int(1),
   652  		RunAttempt: Int(1),
   653  		Event:      String("e"),
   654  		Status:     String("s"),
   655  		Conclusion: String("c"),
   656  		WorkflowID: Int64(1),
   657  		URL:        String("u"),
   658  		HTMLURL:    String("h"),
   659  		PullRequests: []*PullRequest{
   660  			{
   661  				URL:    String("u"),
   662  				ID:     Int64(1),
   663  				Number: Int(1),
   664  				Head: &PullRequestBranch{
   665  					Ref: String("r"),
   666  					SHA: String("s"),
   667  					Repo: &Repository{
   668  						ID:   Int64(1),
   669  						URL:  String("s"),
   670  						Name: String("n"),
   671  					},
   672  				},
   673  				Base: &PullRequestBranch{
   674  					Ref: String("r"),
   675  					SHA: String("s"),
   676  					Repo: &Repository{
   677  						ID:   Int64(1),
   678  						URL:  String("u"),
   679  						Name: String("n"),
   680  					},
   681  				},
   682  			},
   683  		},
   684  		CreatedAt:          &Timestamp{referenceTime},
   685  		UpdatedAt:          &Timestamp{referenceTime},
   686  		RunStartedAt:       &Timestamp{referenceTime},
   687  		JobsURL:            String("j"),
   688  		LogsURL:            String("l"),
   689  		CheckSuiteURL:      String("c"),
   690  		ArtifactsURL:       String("a"),
   691  		CancelURL:          String("c"),
   692  		RerunURL:           String("r"),
   693  		PreviousAttemptURL: String("p"),
   694  		HeadCommit: &HeadCommit{
   695  			Message: String("m"),
   696  			Author: &CommitAuthor{
   697  				Name:  String("n"),
   698  				Email: String("e"),
   699  				Login: String("l"),
   700  			},
   701  			URL:       String("u"),
   702  			Distinct:  Bool(false),
   703  			SHA:       String("s"),
   704  			ID:        String("i"),
   705  			TreeID:    String("tid"),
   706  			Timestamp: &Timestamp{referenceTime},
   707  			Committer: &CommitAuthor{
   708  				Name:  String("n"),
   709  				Email: String("e"),
   710  				Login: String("l"),
   711  			},
   712  		},
   713  		WorkflowURL: String("w"),
   714  		Repository: &Repository{
   715  			ID:   Int64(1),
   716  			URL:  String("u"),
   717  			Name: String("n"),
   718  		},
   719  		HeadRepository: &Repository{
   720  			ID:   Int64(1),
   721  			URL:  String("u"),
   722  			Name: String("n"),
   723  		},
   724  		Actor: &User{
   725  			Login:           String("l"),
   726  			ID:              Int64(1),
   727  			AvatarURL:       String("a"),
   728  			GravatarID:      String("g"),
   729  			Name:            String("n"),
   730  			Company:         String("c"),
   731  			Blog:            String("b"),
   732  			Location:        String("l"),
   733  			Email:           String("e"),
   734  			Hireable:        Bool(true),
   735  			Bio:             String("b"),
   736  			TwitterUsername: String("t"),
   737  			PublicRepos:     Int(1),
   738  			Followers:       Int(1),
   739  			Following:       Int(1),
   740  			CreatedAt:       &Timestamp{referenceTime},
   741  			SuspendedAt:     &Timestamp{referenceTime},
   742  			URL:             String("u"),
   743  		},
   744  		TriggeringActor: &User{
   745  			Login:           String("l2"),
   746  			ID:              Int64(2),
   747  			AvatarURL:       String("a2"),
   748  			GravatarID:      String("g2"),
   749  			Name:            String("n2"),
   750  			Company:         String("c2"),
   751  			Blog:            String("b2"),
   752  			Location:        String("l2"),
   753  			Email:           String("e2"),
   754  			Hireable:        Bool(false),
   755  			Bio:             String("b2"),
   756  			TwitterUsername: String("t2"),
   757  			PublicRepos:     Int(2),
   758  			Followers:       Int(2),
   759  			Following:       Int(2),
   760  			CreatedAt:       &Timestamp{referenceTime},
   761  			SuspendedAt:     &Timestamp{referenceTime},
   762  			URL:             String("u2"),
   763  		},
   764  		ReferencedWorkflows: []*ReferencedWorkflow{
   765  			{
   766  				Path: String("rwfp"),
   767  				SHA:  String("rwfsha"),
   768  				Ref:  String("rwfref"),
   769  			},
   770  		},
   771  	}
   772  
   773  	want := `{
   774  		"id": 1,
   775  		"name": "n",
   776  		"node_id": "nid",
   777  		"head_branch": "hb",
   778  		"head_sha": "hs",
   779  		"run_number": 1,
   780  		"run_attempt": 1,
   781  		"event": "e",
   782  		"status": "s",
   783  		"conclusion": "c",
   784  		"workflow_id": 1,
   785  		"url": "u",
   786  		"html_url": "h",
   787  		"pull_requests": [
   788  			{
   789  				"id":1,
   790  				"number":1,
   791  				"url":"u",
   792  				"head":{
   793  					"ref":"r",
   794  					"sha":"s",
   795  					"repo": {
   796  						"id":1,
   797  						"name":"n",
   798  						"url":"s"
   799  						}
   800  					},
   801  					"base": {
   802  						"ref":"r",
   803  						"sha":"s",
   804  						"repo": {
   805  							"id":1,
   806  							"name":"n",
   807  							"url":"u"
   808  						}
   809  					}
   810  			}
   811  		],
   812  		"created_at": ` + referenceTimeStr + `,
   813  		"updated_at": ` + referenceTimeStr + `,
   814  		"run_started_at": ` + referenceTimeStr + `,
   815  		"jobs_url": "j",
   816  		"logs_url": "l",
   817  		"check_suite_url": "c",
   818  		"artifacts_url": "a",
   819  		"cancel_url": "c",
   820  		"rerun_url": "r",
   821  		"previous_attempt_url": "p",
   822  		"head_commit": {
   823  			"message": "m",
   824  			"author": {
   825  				"name": "n",
   826  				"email": "e",
   827  				"username": "l"
   828  			},
   829  			"url": "u",
   830  			"distinct": false,
   831  			"sha": "s",
   832  			"id": "i",
   833  			"tree_id": "tid",
   834  			"timestamp": ` + referenceTimeStr + `,
   835  			"committer": {
   836  				"name": "n",
   837  				"email": "e",
   838  				"username": "l"
   839  			}
   840  		},
   841  		"workflow_url": "w",
   842  		"repository": {
   843  			"id": 1,
   844  			"url": "u",
   845  			"name": "n"
   846  		},
   847  		"head_repository": {
   848  			"id": 1,
   849  			"url": "u",
   850  			"name": "n"
   851  		},
   852  		"actor": {
   853  			"login": "l",
   854  			"id": 1,
   855  			"avatar_url": "a",
   856  			"gravatar_id": "g",
   857  			"name": "n",
   858  			"company": "c",
   859  			"blog": "b",
   860  			"location": "l",
   861  			"email": "e",
   862  			"hireable": true,
   863  			"bio": "b",
   864  			"twitter_username": "t",
   865  			"public_repos": 1,
   866  			"followers": 1,
   867  			"following": 1,
   868  			"created_at": ` + referenceTimeStr + `,
   869  			"suspended_at": ` + referenceTimeStr + `,
   870  			"url": "u"
   871  		},
   872  		"triggering_actor": {
   873  			"login": "l2",
   874  			"id": 2,
   875  			"avatar_url": "a2",
   876  			"gravatar_id": "g2",
   877  			"name": "n2",
   878  			"company": "c2",
   879  			"blog": "b2",
   880  			"location": "l2",
   881  			"email": "e2",
   882  			"hireable": false,
   883  			"bio": "b2",
   884  			"twitter_username": "t2",
   885  			"public_repos": 2,
   886  			"followers": 2,
   887  			"following": 2,
   888  			"created_at": ` + referenceTimeStr + `,
   889  			"suspended_at": ` + referenceTimeStr + `,
   890  			"url": "u2"
   891  		},
   892  		"referenced_workflows": [
   893  			{
   894  				"path": "rwfp",
   895  				"sha": "rwfsha",
   896  				"ref": "rwfref"
   897  			}
   898  		]
   899  	}`
   900  
   901  	testJSONMarshal(t, u, want)
   902  }
   903  
   904  func TestWorkflowRuns_Marshal(t *testing.T) {
   905  	testJSONMarshal(t, &WorkflowRuns{}, "{}")
   906  
   907  	u := &WorkflowRuns{
   908  		TotalCount: Int(1),
   909  		WorkflowRuns: []*WorkflowRun{
   910  			{
   911  				ID:         Int64(1),
   912  				Name:       String("n"),
   913  				NodeID:     String("nid"),
   914  				HeadBranch: String("hb"),
   915  				HeadSHA:    String("hs"),
   916  				RunNumber:  Int(1),
   917  				RunAttempt: Int(1),
   918  				Event:      String("e"),
   919  				Status:     String("s"),
   920  				Conclusion: String("c"),
   921  				WorkflowID: Int64(1),
   922  				URL:        String("u"),
   923  				HTMLURL:    String("h"),
   924  				PullRequests: []*PullRequest{
   925  					{
   926  						URL:    String("u"),
   927  						ID:     Int64(1),
   928  						Number: Int(1),
   929  						Head: &PullRequestBranch{
   930  							Ref: String("r"),
   931  							SHA: String("s"),
   932  							Repo: &Repository{
   933  								ID:   Int64(1),
   934  								URL:  String("s"),
   935  								Name: String("n"),
   936  							},
   937  						},
   938  						Base: &PullRequestBranch{
   939  							Ref: String("r"),
   940  							SHA: String("s"),
   941  							Repo: &Repository{
   942  								ID:   Int64(1),
   943  								URL:  String("u"),
   944  								Name: String("n"),
   945  							},
   946  						},
   947  					},
   948  				},
   949  				CreatedAt:          &Timestamp{referenceTime},
   950  				UpdatedAt:          &Timestamp{referenceTime},
   951  				RunStartedAt:       &Timestamp{referenceTime},
   952  				JobsURL:            String("j"),
   953  				LogsURL:            String("l"),
   954  				CheckSuiteURL:      String("c"),
   955  				ArtifactsURL:       String("a"),
   956  				CancelURL:          String("c"),
   957  				RerunURL:           String("r"),
   958  				PreviousAttemptURL: String("p"),
   959  				HeadCommit: &HeadCommit{
   960  					Message: String("m"),
   961  					Author: &CommitAuthor{
   962  						Name:  String("n"),
   963  						Email: String("e"),
   964  						Login: String("l"),
   965  					},
   966  					URL:       String("u"),
   967  					Distinct:  Bool(false),
   968  					SHA:       String("s"),
   969  					ID:        String("i"),
   970  					TreeID:    String("tid"),
   971  					Timestamp: &Timestamp{referenceTime},
   972  					Committer: &CommitAuthor{
   973  						Name:  String("n"),
   974  						Email: String("e"),
   975  						Login: String("l"),
   976  					},
   977  				},
   978  				WorkflowURL: String("w"),
   979  				Repository: &Repository{
   980  					ID:   Int64(1),
   981  					URL:  String("u"),
   982  					Name: String("n"),
   983  				},
   984  				HeadRepository: &Repository{
   985  					ID:   Int64(1),
   986  					URL:  String("u"),
   987  					Name: String("n"),
   988  				},
   989  				Actor: &User{
   990  					Login:           String("l"),
   991  					ID:              Int64(1),
   992  					AvatarURL:       String("a"),
   993  					GravatarID:      String("g"),
   994  					Name:            String("n"),
   995  					Company:         String("c"),
   996  					Blog:            String("b"),
   997  					Location:        String("l"),
   998  					Email:           String("e"),
   999  					Hireable:        Bool(true),
  1000  					Bio:             String("b"),
  1001  					TwitterUsername: String("t"),
  1002  					PublicRepos:     Int(1),
  1003  					Followers:       Int(1),
  1004  					Following:       Int(1),
  1005  					CreatedAt:       &Timestamp{referenceTime},
  1006  					SuspendedAt:     &Timestamp{referenceTime},
  1007  					URL:             String("u"),
  1008  				},
  1009  				TriggeringActor: &User{
  1010  					Login:           String("l2"),
  1011  					ID:              Int64(2),
  1012  					AvatarURL:       String("a2"),
  1013  					GravatarID:      String("g2"),
  1014  					Name:            String("n2"),
  1015  					Company:         String("c2"),
  1016  					Blog:            String("b2"),
  1017  					Location:        String("l2"),
  1018  					Email:           String("e2"),
  1019  					Hireable:        Bool(false),
  1020  					Bio:             String("b2"),
  1021  					TwitterUsername: String("t2"),
  1022  					PublicRepos:     Int(2),
  1023  					Followers:       Int(2),
  1024  					Following:       Int(2),
  1025  					CreatedAt:       &Timestamp{referenceTime},
  1026  					SuspendedAt:     &Timestamp{referenceTime},
  1027  					URL:             String("u2"),
  1028  				},
  1029  			},
  1030  		},
  1031  	}
  1032  
  1033  	want := `{
  1034  		"total_count": 1,
  1035  		"workflow_runs": [
  1036  			{
  1037  				"id": 1,
  1038  				"name": "n",
  1039  				"node_id": "nid",
  1040  				"head_branch": "hb",
  1041  				"head_sha": "hs",
  1042  				"run_number": 1,
  1043  				"run_attempt": 1,
  1044  				"event": "e",
  1045  				"status": "s",
  1046  				"conclusion": "c",
  1047  				"workflow_id": 1,
  1048  				"url": "u",
  1049  				"html_url": "h",
  1050  				"pull_requests": [
  1051  					{
  1052  						"id":1,
  1053  						"number":1,
  1054  						"url":"u",
  1055  						"head":{
  1056  							"ref":"r",
  1057  							"sha":"s",
  1058  							"repo": {
  1059  								"id":1,
  1060  								"name":"n",
  1061  								"url":"s"
  1062  								}
  1063  							},
  1064  							"base": {
  1065  								"ref":"r",
  1066  								"sha":"s",
  1067  								"repo": {
  1068  									"id":1,
  1069  									"name":"n",
  1070  									"url":"u"
  1071  								}
  1072  							}
  1073  					}
  1074  				],
  1075  				"created_at": ` + referenceTimeStr + `,
  1076  				"updated_at": ` + referenceTimeStr + `,
  1077  				"run_started_at": ` + referenceTimeStr + `,
  1078  				"jobs_url": "j",
  1079  				"logs_url": "l",
  1080  				"check_suite_url": "c",
  1081  				"artifacts_url": "a",
  1082  				"cancel_url": "c",
  1083  				"rerun_url": "r",
  1084  				"previous_attempt_url": "p",
  1085  				"head_commit": {
  1086  					"message": "m",
  1087  					"author": {
  1088  						"name": "n",
  1089  						"email": "e",
  1090  						"username": "l"
  1091  					},
  1092  					"url": "u",
  1093  					"distinct": false,
  1094  					"sha": "s",
  1095  					"id": "i",
  1096  					"tree_id": "tid",
  1097  					"timestamp": ` + referenceTimeStr + `,
  1098  					"committer": {
  1099  						"name": "n",
  1100  						"email": "e",
  1101  						"username": "l"
  1102  					}
  1103  				},
  1104  				"workflow_url": "w",
  1105  				"repository": {
  1106  					"id": 1,
  1107  					"url": "u",
  1108  					"name": "n"
  1109  				},
  1110  				"head_repository": {
  1111  					"id": 1,
  1112  					"url": "u",
  1113  					"name": "n"
  1114  				},
  1115  				"actor": {
  1116  					"login": "l",
  1117  					"id": 1,
  1118  					"avatar_url": "a",
  1119  					"gravatar_id": "g",
  1120  					"name": "n",
  1121  					"company": "c",
  1122  					"blog": "b",
  1123  					"location": "l",
  1124  					"email": "e",
  1125  					"hireable": true,
  1126  					"bio": "b",
  1127  					"twitter_username": "t",
  1128  					"public_repos": 1,
  1129  					"followers": 1,
  1130  					"following": 1,
  1131  					"created_at": ` + referenceTimeStr + `,
  1132  					"suspended_at": ` + referenceTimeStr + `,
  1133  					"url": "u"
  1134  				},
  1135  				"triggering_actor": {
  1136  					"login": "l2",
  1137  					"id": 2,
  1138  					"avatar_url": "a2",
  1139  					"gravatar_id": "g2",
  1140  					"name": "n2",
  1141  					"company": "c2",
  1142  					"blog": "b2",
  1143  					"location": "l2",
  1144  					"email": "e2",
  1145  					"hireable": false,
  1146  					"bio": "b2",
  1147  					"twitter_username": "t2",
  1148  					"public_repos": 2,
  1149  					"followers": 2,
  1150  					"following": 2,
  1151  					"created_at": ` + referenceTimeStr + `,
  1152  					"suspended_at": ` + referenceTimeStr + `,
  1153  					"url": "u2"
  1154  				}
  1155  			}
  1156  		]
  1157  	}`
  1158  
  1159  	testJSONMarshal(t, u, want)
  1160  }
  1161  
  1162  func TestWorkflowRunBill_Marshal(t *testing.T) {
  1163  	testJSONMarshal(t, &WorkflowRunBill{}, "{}")
  1164  
  1165  	u := &WorkflowRunBill{
  1166  		TotalMS: Int64(1),
  1167  		Jobs:    Int(1),
  1168  	}
  1169  
  1170  	want := `{
  1171  		"total_ms": 1,
  1172  		"jobs": 1
  1173  	}`
  1174  
  1175  	testJSONMarshal(t, u, want)
  1176  }
  1177  
  1178  func TestWorkflowRunBillMap_Marshal(t *testing.T) {
  1179  	testJSONMarshal(t, &WorkflowRunBillMap{}, "{}")
  1180  
  1181  	u := &WorkflowRunBillMap{
  1182  		"UBUNTU": &WorkflowRunBill{
  1183  			TotalMS: Int64(1),
  1184  			Jobs:    Int(1),
  1185  		},
  1186  		"MACOS": &WorkflowRunBill{
  1187  			TotalMS: Int64(1),
  1188  			Jobs:    Int(1),
  1189  		},
  1190  		"WINDOWS": &WorkflowRunBill{
  1191  			TotalMS: Int64(1),
  1192  			Jobs:    Int(1),
  1193  		},
  1194  	}
  1195  
  1196  	want := `{
  1197  		"UBUNTU": {
  1198  			"total_ms": 1,
  1199  			"jobs": 1
  1200  		},
  1201  		"MACOS": {
  1202  			"total_ms": 1,
  1203  			"jobs": 1
  1204  		},
  1205  		"WINDOWS": {
  1206  			"total_ms": 1,
  1207  			"jobs": 1
  1208  		}
  1209  	}`
  1210  
  1211  	testJSONMarshal(t, u, want)
  1212  }
  1213  
  1214  func TestWorkflowRunUsage_Marshal(t *testing.T) {
  1215  	testJSONMarshal(t, &WorkflowRunUsage{}, "{}")
  1216  
  1217  	u := &WorkflowRunUsage{
  1218  		Billable: &WorkflowRunBillMap{
  1219  			"UBUNTU": &WorkflowRunBill{
  1220  				TotalMS: Int64(1),
  1221  				Jobs:    Int(1),
  1222  			},
  1223  			"MACOS": &WorkflowRunBill{
  1224  				TotalMS: Int64(1),
  1225  				Jobs:    Int(1),
  1226  			},
  1227  			"WINDOWS": &WorkflowRunBill{
  1228  				TotalMS: Int64(1),
  1229  				Jobs:    Int(1),
  1230  			},
  1231  		},
  1232  		RunDurationMS: Int64(1),
  1233  	}
  1234  
  1235  	want := `{
  1236  		"billable": {
  1237  			"UBUNTU": {
  1238  				"total_ms": 1,
  1239  				"jobs": 1
  1240  			},
  1241  			"MACOS": {
  1242  				"total_ms": 1,
  1243  				"jobs": 1
  1244  			},
  1245  			"WINDOWS": {
  1246  				"total_ms": 1,
  1247  				"jobs": 1
  1248  			}
  1249  		},
  1250  		"run_duration_ms": 1
  1251  	}`
  1252  
  1253  	testJSONMarshal(t, u, want)
  1254  }
  1255  
  1256  func TestActionService_PendingDeployments(t *testing.T) {
  1257  	client, mux, _, teardown := setup()
  1258  	defer teardown()
  1259  
  1260  	input := &PendingDeploymentsRequest{EnvironmentIDs: []int64{3, 4}, State: "approved", Comment: ""}
  1261  
  1262  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/pending_deployments", func(w http.ResponseWriter, r *http.Request) {
  1263  		v := new(PendingDeploymentsRequest)
  1264  		assertNilError(t, json.NewDecoder(r.Body).Decode(v))
  1265  
  1266  		testMethod(t, r, "POST")
  1267  		if !cmp.Equal(v, input) {
  1268  			t.Errorf("Request body = %+v, want %+v", v, input)
  1269  		}
  1270  
  1271  		fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
  1272  	})
  1273  
  1274  	ctx := context.Background()
  1275  	deployments, _, err := client.Actions.PendingDeployments(ctx, "o", "r", 399444496, input)
  1276  	if err != nil {
  1277  		t.Errorf("Actions.PendingDeployments returned error: %v", err)
  1278  	}
  1279  
  1280  	want := []*Deployment{{ID: Int64(1)}, {ID: Int64(2)}}
  1281  	if !cmp.Equal(deployments, want) {
  1282  		t.Errorf("Actions.PendingDeployments returned %+v, want %+v", deployments, want)
  1283  	}
  1284  
  1285  	const methodName = "PendingDeployments"
  1286  	testBadOptions(t, methodName, func() (err error) {
  1287  		_, _, err = client.Actions.PendingDeployments(ctx, "\n", "\n", 399444496, input)
  1288  		return err
  1289  	})
  1290  
  1291  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
  1292  		got, resp, err := client.Actions.PendingDeployments(ctx, "o", "r", 399444496, input)
  1293  		if got != nil {
  1294  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
  1295  		}
  1296  		return resp, err
  1297  	})
  1298  }