github.com/google/go-github/v60@v60.0.0/github/actions_runners_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  	"testing"
    14  	"time"
    15  
    16  	"github.com/google/go-cmp/cmp"
    17  )
    18  
    19  func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) {
    20  	client, mux, _, teardown := setup()
    21  	defer teardown()
    22  
    23  	mux.HandleFunc("/repos/o/r/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) {
    24  		testMethod(t, r, "GET")
    25  		fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`)
    26  	})
    27  
    28  	ctx := context.Background()
    29  	downloads, _, err := client.Actions.ListRunnerApplicationDownloads(ctx, "o", "r")
    30  	if err != nil {
    31  		t.Errorf("Actions.ListRunnerApplicationDownloads returned error: %v", err)
    32  	}
    33  
    34  	want := []*RunnerApplicationDownload{
    35  		{OS: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")},
    36  		{OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")},
    37  		{OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")},
    38  		{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
    39  		{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
    40  	}
    41  	if !cmp.Equal(downloads, want) {
    42  		t.Errorf("Actions.ListRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
    43  	}
    44  
    45  	const methodName = "ListRunnerApplicationDownloads"
    46  	testBadOptions(t, methodName, func() (err error) {
    47  		_, _, err = client.Actions.ListRunnerApplicationDownloads(ctx, "\n", "\n")
    48  		return err
    49  	})
    50  
    51  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    52  		got, resp, err := client.Actions.ListRunnerApplicationDownloads(ctx, "o", "r")
    53  		if got != nil {
    54  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    55  		}
    56  		return resp, err
    57  	})
    58  }
    59  
    60  func TestActionsService_GenerateOrgJITConfig(t *testing.T) {
    61  	client, mux, _, teardown := setup()
    62  	defer teardown()
    63  
    64  	input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}
    65  
    66  	mux.HandleFunc("/orgs/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
    67  		v := new(GenerateJITConfigRequest)
    68  		assertNilError(t, json.NewDecoder(r.Body).Decode(v))
    69  
    70  		testMethod(t, r, "POST")
    71  		if !cmp.Equal(v, input) {
    72  			t.Errorf("Request body = %+v, want %+v", v, input)
    73  		}
    74  
    75  		fmt.Fprint(w, `{"encoded_jit_config":"foo"}`)
    76  	})
    77  
    78  	ctx := context.Background()
    79  	jitConfig, _, err := client.Actions.GenerateOrgJITConfig(ctx, "o", input)
    80  	if err != nil {
    81  		t.Errorf("Actions.GenerateOrgJITConfig returned error: %v", err)
    82  	}
    83  
    84  	want := &JITRunnerConfig{EncodedJITConfig: String("foo")}
    85  	if !cmp.Equal(jitConfig, want) {
    86  		t.Errorf("Actions.GenerateOrgJITConfig returned %+v, want %+v", jitConfig, want)
    87  	}
    88  
    89  	const methodName = "GenerateOrgJITConfig"
    90  	testBadOptions(t, methodName, func() (err error) {
    91  		_, _, err = client.Actions.GenerateOrgJITConfig(ctx, "\n", input)
    92  		return err
    93  	})
    94  
    95  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    96  		got, resp, err := client.Actions.GenerateOrgJITConfig(ctx, "o", input)
    97  		if got != nil {
    98  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    99  		}
   100  		return resp, err
   101  	})
   102  }
   103  
   104  func TestActionsService_GenerateRepoJITConfig(t *testing.T) {
   105  	client, mux, _, teardown := setup()
   106  	defer teardown()
   107  
   108  	input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}
   109  
   110  	mux.HandleFunc("/repos/o/r/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
   111  		v := new(GenerateJITConfigRequest)
   112  		assertNilError(t, json.NewDecoder(r.Body).Decode(v))
   113  
   114  		testMethod(t, r, "POST")
   115  		if !cmp.Equal(v, input) {
   116  			t.Errorf("Request body = %+v, want %+v", v, input)
   117  		}
   118  
   119  		fmt.Fprint(w, `{"encoded_jit_config":"foo"}`)
   120  	})
   121  
   122  	ctx := context.Background()
   123  	jitConfig, _, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input)
   124  	if err != nil {
   125  		t.Errorf("Actions.GenerateRepoJITConfig returned error: %v", err)
   126  	}
   127  
   128  	want := &JITRunnerConfig{EncodedJITConfig: String("foo")}
   129  	if !cmp.Equal(jitConfig, want) {
   130  		t.Errorf("Actions.GenerateRepoJITConfig returned %+v, want %+v", jitConfig, want)
   131  	}
   132  
   133  	const methodName = "GenerateRepoJITConfig"
   134  	testBadOptions(t, methodName, func() (err error) {
   135  		_, _, err = client.Actions.GenerateRepoJITConfig(ctx, "\n", "\n", input)
   136  		return err
   137  	})
   138  
   139  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   140  		got, resp, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input)
   141  		if got != nil {
   142  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   143  		}
   144  		return resp, err
   145  	})
   146  }
   147  
   148  func TestActionsService_CreateRegistrationToken(t *testing.T) {
   149  	client, mux, _, teardown := setup()
   150  	defer teardown()
   151  
   152  	mux.HandleFunc("/repos/o/r/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) {
   153  		testMethod(t, r, "POST")
   154  		fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`)
   155  	})
   156  
   157  	ctx := context.Background()
   158  	token, _, err := client.Actions.CreateRegistrationToken(ctx, "o", "r")
   159  	if err != nil {
   160  		t.Errorf("Actions.CreateRegistrationToken returned error: %v", err)
   161  	}
   162  
   163  	want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"),
   164  		ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35,
   165  			123000000, time.UTC)}}
   166  	if !cmp.Equal(token, want) {
   167  		t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want)
   168  	}
   169  
   170  	const methodName = "CreateRegistrationToken"
   171  	testBadOptions(t, methodName, func() (err error) {
   172  		_, _, err = client.Actions.CreateRegistrationToken(ctx, "\n", "\n")
   173  		return err
   174  	})
   175  
   176  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   177  		got, resp, err := client.Actions.CreateRegistrationToken(ctx, "o", "r")
   178  		if got != nil {
   179  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   180  		}
   181  		return resp, err
   182  	})
   183  }
   184  
   185  func TestActionsService_ListRunners(t *testing.T) {
   186  	client, mux, _, teardown := setup()
   187  	defer teardown()
   188  
   189  	mux.HandleFunc("/repos/o/r/actions/runners", func(w http.ResponseWriter, r *http.Request) {
   190  		testMethod(t, r, "GET")
   191  		testFormValues(t, r, values{"per_page": "2", "page": "2"})
   192  		fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`)
   193  	})
   194  
   195  	opts := &ListOptions{Page: 2, PerPage: 2}
   196  	ctx := context.Background()
   197  	runners, _, err := client.Actions.ListRunners(ctx, "o", "r", opts)
   198  	if err != nil {
   199  		t.Errorf("Actions.ListRunners returned error: %v", err)
   200  	}
   201  
   202  	want := &Runners{
   203  		TotalCount: 2,
   204  		Runners: []*Runner{
   205  			{ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")},
   206  			{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
   207  		},
   208  	}
   209  	if !cmp.Equal(runners, want) {
   210  		t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
   211  	}
   212  
   213  	const methodName = "ListRunners"
   214  	testBadOptions(t, methodName, func() (err error) {
   215  		_, _, err = client.Actions.ListRunners(ctx, "\n", "\n", opts)
   216  		return err
   217  	})
   218  
   219  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   220  		got, resp, err := client.Actions.ListRunners(ctx, "o", "r", opts)
   221  		if got != nil {
   222  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   223  		}
   224  		return resp, err
   225  	})
   226  }
   227  
   228  func TestActionsService_GetRunner(t *testing.T) {
   229  	client, mux, _, teardown := setup()
   230  	defer teardown()
   231  
   232  	mux.HandleFunc("/repos/o/r/actions/runners/23", func(w http.ResponseWriter, r *http.Request) {
   233  		testMethod(t, r, "GET")
   234  		fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`)
   235  	})
   236  
   237  	ctx := context.Background()
   238  	runner, _, err := client.Actions.GetRunner(ctx, "o", "r", 23)
   239  	if err != nil {
   240  		t.Errorf("Actions.GetRunner returned error: %v", err)
   241  	}
   242  
   243  	want := &Runner{
   244  		ID:     Int64(23),
   245  		Name:   String("MBP"),
   246  		OS:     String("macos"),
   247  		Status: String("online"),
   248  	}
   249  	if !cmp.Equal(runner, want) {
   250  		t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
   251  	}
   252  
   253  	const methodName = "GetRunner"
   254  	testBadOptions(t, methodName, func() (err error) {
   255  		_, _, err = client.Actions.GetRunner(ctx, "\n", "\n", 23)
   256  		return err
   257  	})
   258  
   259  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   260  		got, resp, err := client.Actions.GetRunner(ctx, "o", "r", 23)
   261  		if got != nil {
   262  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   263  		}
   264  		return resp, err
   265  	})
   266  }
   267  
   268  func TestActionsService_CreateRemoveToken(t *testing.T) {
   269  	client, mux, _, teardown := setup()
   270  	defer teardown()
   271  
   272  	mux.HandleFunc("/repos/o/r/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) {
   273  		testMethod(t, r, "POST")
   274  		fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`)
   275  	})
   276  
   277  	ctx := context.Background()
   278  	token, _, err := client.Actions.CreateRemoveToken(ctx, "o", "r")
   279  	if err != nil {
   280  		t.Errorf("Actions.CreateRemoveToken returned error: %v", err)
   281  	}
   282  
   283  	want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
   284  	if !cmp.Equal(token, want) {
   285  		t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
   286  	}
   287  
   288  	const methodName = "CreateRemoveToken"
   289  	testBadOptions(t, methodName, func() (err error) {
   290  		_, _, err = client.Actions.CreateRemoveToken(ctx, "\n", "\n")
   291  		return err
   292  	})
   293  
   294  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   295  		got, resp, err := client.Actions.CreateRemoveToken(ctx, "o", "r")
   296  		if got != nil {
   297  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   298  		}
   299  		return resp, err
   300  	})
   301  }
   302  
   303  func TestActionsService_RemoveRunner(t *testing.T) {
   304  	client, mux, _, teardown := setup()
   305  	defer teardown()
   306  
   307  	mux.HandleFunc("/repos/o/r/actions/runners/21", func(w http.ResponseWriter, r *http.Request) {
   308  		testMethod(t, r, "DELETE")
   309  	})
   310  
   311  	ctx := context.Background()
   312  	_, err := client.Actions.RemoveRunner(ctx, "o", "r", 21)
   313  	if err != nil {
   314  		t.Errorf("Actions.RemoveRunner returned error: %v", err)
   315  	}
   316  
   317  	const methodName = "RemoveRunner"
   318  	testBadOptions(t, methodName, func() (err error) {
   319  		_, err = client.Actions.RemoveRunner(ctx, "\n", "\n", 21)
   320  		return err
   321  	})
   322  
   323  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   324  		return client.Actions.RemoveRunner(ctx, "o", "r", 21)
   325  	})
   326  }
   327  
   328  func TestActionsService_ListOrganizationRunnerApplicationDownloads(t *testing.T) {
   329  	client, mux, _, teardown := setup()
   330  	defer teardown()
   331  
   332  	mux.HandleFunc("/orgs/o/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) {
   333  		testMethod(t, r, "GET")
   334  		fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`)
   335  	})
   336  
   337  	ctx := context.Background()
   338  	downloads, _, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o")
   339  	if err != nil {
   340  		t.Errorf("Actions.ListRunnerApplicationDownloads returned error: %v", err)
   341  	}
   342  
   343  	want := []*RunnerApplicationDownload{
   344  		{OS: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")},
   345  		{OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")},
   346  		{OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")},
   347  		{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
   348  		{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
   349  	}
   350  	if !cmp.Equal(downloads, want) {
   351  		t.Errorf("Actions.ListOrganizationRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
   352  	}
   353  
   354  	const methodName = "ListOrganizationRunnerApplicationDownloads"
   355  	testBadOptions(t, methodName, func() (err error) {
   356  		_, _, err = client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "\n")
   357  		return err
   358  	})
   359  
   360  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   361  		got, resp, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o")
   362  		if got != nil {
   363  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   364  		}
   365  		return resp, err
   366  	})
   367  }
   368  
   369  func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) {
   370  	client, mux, _, teardown := setup()
   371  	defer teardown()
   372  
   373  	mux.HandleFunc("/orgs/o/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) {
   374  		testMethod(t, r, "POST")
   375  		fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`)
   376  	})
   377  
   378  	ctx := context.Background()
   379  	token, _, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o")
   380  	if err != nil {
   381  		t.Errorf("Actions.CreateRegistrationToken returned error: %v", err)
   382  	}
   383  
   384  	want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"),
   385  		ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35,
   386  			123000000, time.UTC)}}
   387  	if !cmp.Equal(token, want) {
   388  		t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want)
   389  	}
   390  
   391  	const methodName = "CreateOrganizationRegistrationToken"
   392  	testBadOptions(t, methodName, func() (err error) {
   393  		_, _, err = client.Actions.CreateOrganizationRegistrationToken(ctx, "\n")
   394  		return err
   395  	})
   396  
   397  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   398  		got, resp, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o")
   399  		if got != nil {
   400  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   401  		}
   402  		return resp, err
   403  	})
   404  }
   405  
   406  func TestActionsService_ListOrganizationRunners(t *testing.T) {
   407  	client, mux, _, teardown := setup()
   408  	defer teardown()
   409  
   410  	mux.HandleFunc("/orgs/o/actions/runners", func(w http.ResponseWriter, r *http.Request) {
   411  		testMethod(t, r, "GET")
   412  		testFormValues(t, r, values{"per_page": "2", "page": "2"})
   413  		fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`)
   414  	})
   415  
   416  	opts := &ListOptions{Page: 2, PerPage: 2}
   417  	ctx := context.Background()
   418  	runners, _, err := client.Actions.ListOrganizationRunners(ctx, "o", opts)
   419  	if err != nil {
   420  		t.Errorf("Actions.ListRunners returned error: %v", err)
   421  	}
   422  
   423  	want := &Runners{
   424  		TotalCount: 2,
   425  		Runners: []*Runner{
   426  			{ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")},
   427  			{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
   428  		},
   429  	}
   430  	if !cmp.Equal(runners, want) {
   431  		t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
   432  	}
   433  
   434  	const methodName = "ListOrganizationRunners"
   435  	testBadOptions(t, methodName, func() (err error) {
   436  		_, _, err = client.Actions.ListOrganizationRunners(ctx, "\n", opts)
   437  		return err
   438  	})
   439  
   440  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   441  		got, resp, err := client.Actions.ListOrganizationRunners(ctx, "o", opts)
   442  		if got != nil {
   443  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   444  		}
   445  		return resp, err
   446  	})
   447  }
   448  
   449  func TestActionsService_GetOrganizationRunner(t *testing.T) {
   450  	client, mux, _, teardown := setup()
   451  	defer teardown()
   452  
   453  	mux.HandleFunc("/orgs/o/actions/runners/23", func(w http.ResponseWriter, r *http.Request) {
   454  		testMethod(t, r, "GET")
   455  		fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`)
   456  	})
   457  
   458  	ctx := context.Background()
   459  	runner, _, err := client.Actions.GetOrganizationRunner(ctx, "o", 23)
   460  	if err != nil {
   461  		t.Errorf("Actions.GetRunner returned error: %v", err)
   462  	}
   463  
   464  	want := &Runner{
   465  		ID:     Int64(23),
   466  		Name:   String("MBP"),
   467  		OS:     String("macos"),
   468  		Status: String("online"),
   469  	}
   470  	if !cmp.Equal(runner, want) {
   471  		t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
   472  	}
   473  
   474  	const methodName = "GetOrganizationRunner"
   475  	testBadOptions(t, methodName, func() (err error) {
   476  		_, _, err = client.Actions.GetOrganizationRunner(ctx, "\n", 23)
   477  		return err
   478  	})
   479  
   480  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   481  		got, resp, err := client.Actions.GetOrganizationRunner(ctx, "o", 23)
   482  		if got != nil {
   483  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   484  		}
   485  		return resp, err
   486  	})
   487  }
   488  
   489  func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) {
   490  	client, mux, _, teardown := setup()
   491  	defer teardown()
   492  
   493  	mux.HandleFunc("/orgs/o/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) {
   494  		testMethod(t, r, "POST")
   495  		fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`)
   496  	})
   497  
   498  	ctx := context.Background()
   499  	token, _, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o")
   500  	if err != nil {
   501  		t.Errorf("Actions.CreateRemoveToken returned error: %v", err)
   502  	}
   503  
   504  	want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
   505  	if !cmp.Equal(token, want) {
   506  		t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
   507  	}
   508  
   509  	const methodName = "CreateOrganizationRemoveToken"
   510  	testBadOptions(t, methodName, func() (err error) {
   511  		_, _, err = client.Actions.CreateOrganizationRemoveToken(ctx, "\n")
   512  		return err
   513  	})
   514  
   515  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   516  		got, resp, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o")
   517  		if got != nil {
   518  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   519  		}
   520  		return resp, err
   521  	})
   522  }
   523  
   524  func TestActionsService_RemoveOrganizationRunner(t *testing.T) {
   525  	client, mux, _, teardown := setup()
   526  	defer teardown()
   527  
   528  	mux.HandleFunc("/orgs/o/actions/runners/21", func(w http.ResponseWriter, r *http.Request) {
   529  		testMethod(t, r, "DELETE")
   530  	})
   531  
   532  	ctx := context.Background()
   533  	_, err := client.Actions.RemoveOrganizationRunner(ctx, "o", 21)
   534  	if err != nil {
   535  		t.Errorf("Actions.RemoveOganizationRunner returned error: %v", err)
   536  	}
   537  
   538  	const methodName = "RemoveOrganizationRunner"
   539  	testBadOptions(t, methodName, func() (err error) {
   540  		_, err = client.Actions.RemoveOrganizationRunner(ctx, "\n", 21)
   541  		return err
   542  	})
   543  
   544  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
   545  		return client.Actions.RemoveOrganizationRunner(ctx, "o", 21)
   546  	})
   547  }
   548  
   549  func TestRunnerApplicationDownload_Marshal(t *testing.T) {
   550  	testJSONMarshal(t, &RunnerApplicationDownload{}, "{}")
   551  
   552  	u := &RunnerApplicationDownload{
   553  		OS:                String("o"),
   554  		Architecture:      String("a"),
   555  		DownloadURL:       String("d"),
   556  		Filename:          String("f"),
   557  		TempDownloadToken: String("t"),
   558  		SHA256Checksum:    String("s"),
   559  	}
   560  
   561  	want := `{
   562  		"os": "o",
   563  		"architecture": "a",
   564  		"download_url": "d",
   565  		"filename": "f",
   566  		"temp_download_token": "t",
   567  		"sha256_checksum": "s"
   568  	}`
   569  
   570  	testJSONMarshal(t, u, want)
   571  }
   572  
   573  func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
   574  	testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}")
   575  
   576  	u := &ActionsEnabledOnOrgRepos{
   577  		TotalCount: 1,
   578  		Repositories: []*Repository{
   579  			{
   580  				ID:   Int64(1),
   581  				URL:  String("u"),
   582  				Name: String("n"),
   583  			},
   584  		},
   585  	}
   586  
   587  	want := `{
   588  		"total_count": 1,
   589  		"repositories": [
   590  			{
   591  				"id": 1,
   592  				"url": "u",
   593  				"name": "n"
   594  			}
   595  		]
   596  	}`
   597  
   598  	testJSONMarshal(t, u, want)
   599  }
   600  
   601  func TestRegistrationToken_Marshal(t *testing.T) {
   602  	testJSONMarshal(t, &RegistrationToken{}, "{}")
   603  
   604  	u := &RegistrationToken{
   605  		Token:     String("t"),
   606  		ExpiresAt: &Timestamp{referenceTime},
   607  	}
   608  
   609  	want := `{
   610  		"token": "t",
   611  		"expires_at": ` + referenceTimeStr + `
   612  	}`
   613  
   614  	testJSONMarshal(t, u, want)
   615  }
   616  
   617  func TestRunnerLabels_Marshal(t *testing.T) {
   618  	testJSONMarshal(t, &RunnerLabels{}, "{}")
   619  
   620  	u := &RunnerLabels{
   621  		ID:   Int64(1),
   622  		Name: String("n"),
   623  		Type: String("t"),
   624  	}
   625  
   626  	want := `{
   627  		"id": 1,
   628  		"name": "n",
   629  		"type": "t"
   630  	}`
   631  
   632  	testJSONMarshal(t, u, want)
   633  }
   634  
   635  func TestRunner_Marshal(t *testing.T) {
   636  	testJSONMarshal(t, &Runner{}, "{}")
   637  
   638  	u := &Runner{
   639  		ID:     Int64(1),
   640  		Name:   String("n"),
   641  		OS:     String("o"),
   642  		Status: String("s"),
   643  		Busy:   Bool(false),
   644  		Labels: []*RunnerLabels{
   645  			{
   646  				ID:   Int64(1),
   647  				Name: String("n"),
   648  				Type: String("t"),
   649  			},
   650  		},
   651  	}
   652  
   653  	want := `{
   654  		"id": 1,
   655  		"name": "n",
   656  		"os": "o",
   657  		"status": "s",
   658  		"busy": false,
   659  		"labels": [
   660  			{
   661  				"id": 1,
   662  				"name": "n",
   663  				"type": "t"
   664  			}
   665  		]
   666  	}`
   667  
   668  	testJSONMarshal(t, u, want)
   669  }
   670  
   671  func TestRunners_Marshal(t *testing.T) {
   672  	testJSONMarshal(t, &Runners{}, "{}")
   673  
   674  	u := &Runners{
   675  		TotalCount: 1,
   676  		Runners: []*Runner{
   677  			{
   678  				ID:     Int64(1),
   679  				Name:   String("n"),
   680  				OS:     String("o"),
   681  				Status: String("s"),
   682  				Busy:   Bool(false),
   683  				Labels: []*RunnerLabels{
   684  					{
   685  						ID:   Int64(1),
   686  						Name: String("n"),
   687  						Type: String("t"),
   688  					},
   689  				},
   690  			},
   691  		},
   692  	}
   693  
   694  	want := `{
   695  		"total_count": 1,
   696  		"runners": [
   697  			{
   698  				"id": 1,
   699  		"name": "n",
   700  		"os": "o",
   701  		"status": "s",
   702  		"busy": false,
   703  		"labels": [
   704  			{
   705  				"id": 1,
   706  				"name": "n",
   707  				"type": "t"
   708  			}
   709  		]
   710  			}
   711  		]
   712  	}`
   713  
   714  	testJSONMarshal(t, u, want)
   715  }
   716  
   717  func TestRemoveToken_Marshal(t *testing.T) {
   718  	testJSONMarshal(t, &RemoveToken{}, "{}")
   719  
   720  	u := &RemoveToken{
   721  		Token:     String("t"),
   722  		ExpiresAt: &Timestamp{referenceTime},
   723  	}
   724  
   725  	want := `{
   726  		"token": "t",
   727  		"expires_at": ` + referenceTimeStr + `
   728  	}`
   729  
   730  	testJSONMarshal(t, u, want)
   731  }