|
| 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 | + "fmt" |
| 11 | + "net/http" |
| 12 | + "reflect" |
| 13 | + "testing" |
| 14 | + "time" |
| 15 | +) |
| 16 | + |
| 17 | +func TestEnterpriseService_CreateRegistrationToken(t *testing.T) { |
| 18 | + client, mux, _, teardown := setup() |
| 19 | + defer teardown() |
| 20 | + |
| 21 | + mux.HandleFunc("/enterprises/e/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { |
| 22 | + testMethod(t, r, "POST") |
| 23 | + fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) |
| 24 | + }) |
| 25 | + |
| 26 | + token, _, err := client.Enterprise.CreateRegistrationToken(context.Background(), "e") |
| 27 | + if err != nil { |
| 28 | + t.Errorf("Enterprise.CreateRegistrationToken returned error: %v", err) |
| 29 | + } |
| 30 | + |
| 31 | + want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), |
| 32 | + ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, |
| 33 | + 123000000, time.UTC)}} |
| 34 | + if !reflect.DeepEqual(token, want) { |
| 35 | + t.Errorf("Enterprise.CreateRegistrationToken returned %+v, want %+v", token, want) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func TestEnterpriseService_ListRunners(t *testing.T) { |
| 40 | + client, mux, _, teardown := setup() |
| 41 | + defer teardown() |
| 42 | + |
| 43 | + mux.HandleFunc("/enterprises/e/actions/runners", func(w http.ResponseWriter, r *http.Request) { |
| 44 | + testMethod(t, r, "GET") |
| 45 | + testFormValues(t, r, values{"per_page": "2", "page": "2"}) |
| 46 | + fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`) |
| 47 | + }) |
| 48 | + |
| 49 | + opts := &ListOptions{Page: 2, PerPage: 2} |
| 50 | + runners, _, err := client.Enterprise.ListRunners(context.Background(), "e", opts) |
| 51 | + if err != nil { |
| 52 | + t.Errorf("Enterprise.ListRunners returned error: %v", err) |
| 53 | + } |
| 54 | + |
| 55 | + want := &Runners{ |
| 56 | + TotalCount: 2, |
| 57 | + Runners: []*Runner{ |
| 58 | + {ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")}, |
| 59 | + {ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")}, |
| 60 | + }, |
| 61 | + } |
| 62 | + if !reflect.DeepEqual(runners, want) { |
| 63 | + t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want) |
| 64 | + } |
| 65 | +} |
0 commit comments