...

Source file src/github.com/google/go-github/v55/github/actions_workflow_runs_test.go

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

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

View as plain text