github.com/google/go-github/v53@v53.2.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, true)
   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, true)
   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, false)
   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, true)
   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, true)
   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, true)
   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, true)
   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, false)
   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, true)
   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, true)
   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  	}
   745  
   746  	want := `{
   747  		"id": 1,
   748  		"name": "n",
   749  		"node_id": "nid",
   750  		"head_branch": "hb",
   751  		"head_sha": "hs",
   752  		"run_number": 1,
   753  		"run_attempt": 1,
   754  		"event": "e",
   755  		"status": "s",
   756  		"conclusion": "c",
   757  		"workflow_id": 1,
   758  		"url": "u",
   759  		"html_url": "h",
   760  		"pull_requests": [
   761  			{
   762  				"id":1,
   763  				"number":1,
   764  				"url":"u",
   765  				"head":{
   766  					"ref":"r",
   767  					"sha":"s",
   768  					"repo": {
   769  						"id":1,
   770  						"name":"n",
   771  						"url":"s"
   772  						}
   773  					},
   774  					"base": {
   775  						"ref":"r",
   776  						"sha":"s",
   777  						"repo": {
   778  							"id":1,
   779  							"name":"n",
   780  							"url":"u"
   781  						}
   782  					}
   783  			}
   784  		],
   785  		"created_at": ` + referenceTimeStr + `,
   786  		"updated_at": ` + referenceTimeStr + `,
   787  		"run_started_at": ` + referenceTimeStr + `,
   788  		"jobs_url": "j",
   789  		"logs_url": "l",
   790  		"check_suite_url": "c",
   791  		"artifacts_url": "a",
   792  		"cancel_url": "c",
   793  		"rerun_url": "r",
   794  		"previous_attempt_url": "p",
   795  		"head_commit": {
   796  			"message": "m",
   797  			"author": {
   798  				"name": "n",
   799  				"email": "e",
   800  				"username": "l"
   801  			},
   802  			"url": "u",
   803  			"distinct": false,
   804  			"sha": "s",
   805  			"id": "i",
   806  			"tree_id": "tid",
   807  			"timestamp": ` + referenceTimeStr + `,
   808  			"committer": {
   809  				"name": "n",
   810  				"email": "e",
   811  				"username": "l"
   812  			}
   813  		},
   814  		"workflow_url": "w",
   815  		"repository": {
   816  			"id": 1,
   817  			"url": "u",
   818  			"name": "n"
   819  		},
   820  		"head_repository": {
   821  			"id": 1,
   822  			"url": "u",
   823  			"name": "n"
   824  		},
   825  		"actor": {
   826  			"login": "l",
   827  			"id": 1,
   828  			"avatar_url": "a",
   829  			"gravatar_id": "g",
   830  			"name": "n",
   831  			"company": "c",
   832  			"blog": "b",
   833  			"location": "l",
   834  			"email": "e",
   835  			"hireable": true,
   836  			"bio": "b",
   837  			"twitter_username": "t",
   838  			"public_repos": 1,
   839  			"followers": 1,
   840  			"following": 1,
   841  			"created_at": ` + referenceTimeStr + `,
   842  			"suspended_at": ` + referenceTimeStr + `,
   843  			"url": "u"
   844  		}
   845  	}`
   846  
   847  	testJSONMarshal(t, u, want)
   848  }
   849  
   850  func TestWorkflowRuns_Marshal(t *testing.T) {
   851  	testJSONMarshal(t, &WorkflowRuns{}, "{}")
   852  
   853  	u := &WorkflowRuns{
   854  		TotalCount: Int(1),
   855  		WorkflowRuns: []*WorkflowRun{
   856  			{
   857  				ID:         Int64(1),
   858  				Name:       String("n"),
   859  				NodeID:     String("nid"),
   860  				HeadBranch: String("hb"),
   861  				HeadSHA:    String("hs"),
   862  				RunNumber:  Int(1),
   863  				RunAttempt: Int(1),
   864  				Event:      String("e"),
   865  				Status:     String("s"),
   866  				Conclusion: String("c"),
   867  				WorkflowID: Int64(1),
   868  				URL:        String("u"),
   869  				HTMLURL:    String("h"),
   870  				PullRequests: []*PullRequest{
   871  					{
   872  						URL:    String("u"),
   873  						ID:     Int64(1),
   874  						Number: Int(1),
   875  						Head: &PullRequestBranch{
   876  							Ref: String("r"),
   877  							SHA: String("s"),
   878  							Repo: &Repository{
   879  								ID:   Int64(1),
   880  								URL:  String("s"),
   881  								Name: String("n"),
   882  							},
   883  						},
   884  						Base: &PullRequestBranch{
   885  							Ref: String("r"),
   886  							SHA: String("s"),
   887  							Repo: &Repository{
   888  								ID:   Int64(1),
   889  								URL:  String("u"),
   890  								Name: String("n"),
   891  							},
   892  						},
   893  					},
   894  				},
   895  				CreatedAt:          &Timestamp{referenceTime},
   896  				UpdatedAt:          &Timestamp{referenceTime},
   897  				RunStartedAt:       &Timestamp{referenceTime},
   898  				JobsURL:            String("j"),
   899  				LogsURL:            String("l"),
   900  				CheckSuiteURL:      String("c"),
   901  				ArtifactsURL:       String("a"),
   902  				CancelURL:          String("c"),
   903  				RerunURL:           String("r"),
   904  				PreviousAttemptURL: String("p"),
   905  				HeadCommit: &HeadCommit{
   906  					Message: String("m"),
   907  					Author: &CommitAuthor{
   908  						Name:  String("n"),
   909  						Email: String("e"),
   910  						Login: String("l"),
   911  					},
   912  					URL:       String("u"),
   913  					Distinct:  Bool(false),
   914  					SHA:       String("s"),
   915  					ID:        String("i"),
   916  					TreeID:    String("tid"),
   917  					Timestamp: &Timestamp{referenceTime},
   918  					Committer: &CommitAuthor{
   919  						Name:  String("n"),
   920  						Email: String("e"),
   921  						Login: String("l"),
   922  					},
   923  				},
   924  				WorkflowURL: String("w"),
   925  				Repository: &Repository{
   926  					ID:   Int64(1),
   927  					URL:  String("u"),
   928  					Name: String("n"),
   929  				},
   930  				HeadRepository: &Repository{
   931  					ID:   Int64(1),
   932  					URL:  String("u"),
   933  					Name: String("n"),
   934  				},
   935  				Actor: &User{
   936  					Login:           String("l"),
   937  					ID:              Int64(1),
   938  					AvatarURL:       String("a"),
   939  					GravatarID:      String("g"),
   940  					Name:            String("n"),
   941  					Company:         String("c"),
   942  					Blog:            String("b"),
   943  					Location:        String("l"),
   944  					Email:           String("e"),
   945  					Hireable:        Bool(true),
   946  					Bio:             String("b"),
   947  					TwitterUsername: String("t"),
   948  					PublicRepos:     Int(1),
   949  					Followers:       Int(1),
   950  					Following:       Int(1),
   951  					CreatedAt:       &Timestamp{referenceTime},
   952  					SuspendedAt:     &Timestamp{referenceTime},
   953  					URL:             String("u"),
   954  				},
   955  			},
   956  		},
   957  	}
   958  
   959  	want := `{
   960  		"total_count": 1,
   961  		"workflow_runs": [
   962  			{
   963  				"id": 1,
   964  				"name": "n",
   965  				"node_id": "nid",
   966  				"head_branch": "hb",
   967  				"head_sha": "hs",
   968  				"run_number": 1,
   969  				"run_attempt": 1,
   970  				"event": "e",
   971  				"status": "s",
   972  				"conclusion": "c",
   973  				"workflow_id": 1,
   974  				"url": "u",
   975  				"html_url": "h",
   976  				"pull_requests": [
   977  					{
   978  						"id":1,
   979  						"number":1,
   980  						"url":"u",
   981  						"head":{
   982  							"ref":"r",
   983  							"sha":"s",
   984  							"repo": {
   985  								"id":1,
   986  								"name":"n",
   987  								"url":"s"
   988  								}
   989  							},
   990  							"base": {
   991  								"ref":"r",
   992  								"sha":"s",
   993  								"repo": {
   994  									"id":1,
   995  									"name":"n",
   996  									"url":"u"
   997  								}
   998  							}
   999  					}
  1000  				],
  1001  				"created_at": ` + referenceTimeStr + `,
  1002  				"updated_at": ` + referenceTimeStr + `,
  1003  				"run_started_at": ` + referenceTimeStr + `,
  1004  				"jobs_url": "j",
  1005  				"logs_url": "l",
  1006  				"check_suite_url": "c",
  1007  				"artifacts_url": "a",
  1008  				"cancel_url": "c",
  1009  				"rerun_url": "r",
  1010  				"previous_attempt_url": "p",
  1011  				"head_commit": {
  1012  					"message": "m",
  1013  					"author": {
  1014  						"name": "n",
  1015  						"email": "e",
  1016  						"username": "l"
  1017  					},
  1018  					"url": "u",
  1019  					"distinct": false,
  1020  					"sha": "s",
  1021  					"id": "i",
  1022  					"tree_id": "tid",
  1023  					"timestamp": ` + referenceTimeStr + `,
  1024  					"committer": {
  1025  						"name": "n",
  1026  						"email": "e",
  1027  						"username": "l"
  1028  					}
  1029  				},
  1030  				"workflow_url": "w",
  1031  				"repository": {
  1032  					"id": 1,
  1033  					"url": "u",
  1034  					"name": "n"
  1035  				},
  1036  				"head_repository": {
  1037  					"id": 1,
  1038  					"url": "u",
  1039  					"name": "n"
  1040  				},
  1041  				"actor": {
  1042  					"login": "l",
  1043  					"id": 1,
  1044  					"avatar_url": "a",
  1045  					"gravatar_id": "g",
  1046  					"name": "n",
  1047  					"company": "c",
  1048  					"blog": "b",
  1049  					"location": "l",
  1050  					"email": "e",
  1051  					"hireable": true,
  1052  					"bio": "b",
  1053  					"twitter_username": "t",
  1054  					"public_repos": 1,
  1055  					"followers": 1,
  1056  					"following": 1,
  1057  					"created_at": ` + referenceTimeStr + `,
  1058  					"suspended_at": ` + referenceTimeStr + `,
  1059  					"url": "u"
  1060  				}
  1061  			}
  1062  		]
  1063  	}`
  1064  
  1065  	testJSONMarshal(t, u, want)
  1066  }
  1067  
  1068  func TestWorkflowRunBill_Marshal(t *testing.T) {
  1069  	testJSONMarshal(t, &WorkflowRunBill{}, "{}")
  1070  
  1071  	u := &WorkflowRunBill{
  1072  		TotalMS: Int64(1),
  1073  		Jobs:    Int(1),
  1074  	}
  1075  
  1076  	want := `{
  1077  		"total_ms": 1,
  1078  		"jobs": 1
  1079  	}`
  1080  
  1081  	testJSONMarshal(t, u, want)
  1082  }
  1083  
  1084  func TestWorkflowRunBillMap_Marshal(t *testing.T) {
  1085  	testJSONMarshal(t, &WorkflowRunBillMap{}, "{}")
  1086  
  1087  	u := &WorkflowRunBillMap{
  1088  		"UBUNTU": &WorkflowRunBill{
  1089  			TotalMS: Int64(1),
  1090  			Jobs:    Int(1),
  1091  		},
  1092  		"MACOS": &WorkflowRunBill{
  1093  			TotalMS: Int64(1),
  1094  			Jobs:    Int(1),
  1095  		},
  1096  		"WINDOWS": &WorkflowRunBill{
  1097  			TotalMS: Int64(1),
  1098  			Jobs:    Int(1),
  1099  		},
  1100  	}
  1101  
  1102  	want := `{
  1103  		"UBUNTU": {
  1104  			"total_ms": 1,
  1105  			"jobs": 1
  1106  		},
  1107  		"MACOS": {
  1108  			"total_ms": 1,
  1109  			"jobs": 1
  1110  		},
  1111  		"WINDOWS": {
  1112  			"total_ms": 1,
  1113  			"jobs": 1
  1114  		}
  1115  	}`
  1116  
  1117  	testJSONMarshal(t, u, want)
  1118  }
  1119  
  1120  func TestWorkflowRunUsage_Marshal(t *testing.T) {
  1121  	testJSONMarshal(t, &WorkflowRunUsage{}, "{}")
  1122  
  1123  	u := &WorkflowRunUsage{
  1124  		Billable: &WorkflowRunBillMap{
  1125  			"UBUNTU": &WorkflowRunBill{
  1126  				TotalMS: Int64(1),
  1127  				Jobs:    Int(1),
  1128  			},
  1129  			"MACOS": &WorkflowRunBill{
  1130  				TotalMS: Int64(1),
  1131  				Jobs:    Int(1),
  1132  			},
  1133  			"WINDOWS": &WorkflowRunBill{
  1134  				TotalMS: Int64(1),
  1135  				Jobs:    Int(1),
  1136  			},
  1137  		},
  1138  		RunDurationMS: Int64(1),
  1139  	}
  1140  
  1141  	want := `{
  1142  		"billable": {
  1143  			"UBUNTU": {
  1144  				"total_ms": 1,
  1145  				"jobs": 1
  1146  			},
  1147  			"MACOS": {
  1148  				"total_ms": 1,
  1149  				"jobs": 1
  1150  			},
  1151  			"WINDOWS": {
  1152  				"total_ms": 1,
  1153  				"jobs": 1
  1154  			}
  1155  		},
  1156  		"run_duration_ms": 1
  1157  	}`
  1158  
  1159  	testJSONMarshal(t, u, want)
  1160  }
  1161  
  1162  func TestActionService_PendingDeployments(t *testing.T) {
  1163  	client, mux, _, teardown := setup()
  1164  	defer teardown()
  1165  
  1166  	input := &PendingDeploymentsRequest{EnvironmentIDs: []int64{3, 4}, State: "approved", Comment: ""}
  1167  
  1168  	mux.HandleFunc("/repos/o/r/actions/runs/399444496/pending_deployments", func(w http.ResponseWriter, r *http.Request) {
  1169  		v := new(PendingDeploymentsRequest)
  1170  		json.NewDecoder(r.Body).Decode(v)
  1171  
  1172  		testMethod(t, r, "POST")
  1173  		if !cmp.Equal(v, input) {
  1174  			t.Errorf("Request body = %+v, want %+v", v, input)
  1175  		}
  1176  
  1177  		fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
  1178  	})
  1179  
  1180  	ctx := context.Background()
  1181  	deployments, _, err := client.Actions.PendingDeployments(ctx, "o", "r", 399444496, input)
  1182  	if err != nil {
  1183  		t.Errorf("Actions.PendingDeployments returned error: %v", err)
  1184  	}
  1185  
  1186  	want := []*Deployment{{ID: Int64(1)}, {ID: Int64(2)}}
  1187  	if !cmp.Equal(deployments, want) {
  1188  		t.Errorf("Actions.PendingDeployments returned %+v, want %+v", deployments, want)
  1189  	}
  1190  
  1191  	const methodName = "PendingDeployments"
  1192  	testBadOptions(t, methodName, func() (err error) {
  1193  		_, _, err = client.Actions.PendingDeployments(ctx, "\n", "\n", 399444496, input)
  1194  		return err
  1195  	})
  1196  
  1197  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
  1198  		got, resp, err := client.Actions.PendingDeployments(ctx, "o", "r", 399444496, input)
  1199  		if got != nil {
  1200  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
  1201  		}
  1202  		return resp, err
  1203  	})
  1204  }