Repository: xanzy/go-gitlab
Pull request #1459 (2022-05-02 06:40:19)

Support `token_expires_at` field in Runners API


Patch:
diff --git a/runners.go b/runners.go
index 35957d4..a56db05 100644
--- a/runners.go
+++ b/runners.go
@@ -34,17 +34,18 @@ type RunnersService struct {
 //
 // GitLab API docs: https://docs.gitlab.com/ce/api/runners.html
 type Runner struct {
-	ID          int    `json:"id"`
-	Description string `json:"description"`
-	Active      bool   `json:"active"`
-	Paused      bool   `json:"paused"`
-	IsShared    bool   `json:"is_shared"`
-	IPAddress   string `json:"ip_address"`
-	RunnerType  string `json:"runner_type"`
-	Name        string `json:"name"`
-	Online      bool   `json:"online"`
-	Status      string `json:"status"`
-	Token       string `json:"token"`
+	ID             int        `json:"id"`
+	Description    string     `json:"description"`
+	Active         bool       `json:"active"`
+	Paused         bool       `json:"paused"`
+	IsShared       bool       `json:"is_shared"`
+	IPAddress      string     `json:"ip_address"`
+	RunnerType     string     `json:"runner_type"`
+	Name           string     `json:"name"`
+	Online         bool       `json:"online"`
+	Status         string     `json:"status"`
+	Token          string     `json:"token"`
+	TokenExpiresAt *time.Time `json:"token_expires_at"`
 }
 
 // RunnerDetails represents the GitLab CI runner details.
@@ -497,7 +498,8 @@ func (s *RunnersService) VerifyRegisteredRunner(opt *VerifyRegisteredRunnerOptio
 }
 
 type RunnerRegistrationToken struct {
-	Token *string `url:"token" json:"token"`
+	Token          *string    `url:"token" json:"token"`
+	TokenExpiresAt *time.Time `url:"token_expires_at" json:"token_expires_at"`
 }
 
 // ResetInstanceRunnerRegistrationToken resets the instance runner registration
@@ -570,7 +572,8 @@ func (s *RunnersService) ResetProjectRunnerRegistrationToken(pid interface{}, op
 }
 
 type RunnerAuthenticationToken struct {
-	Token *string `url:"token" json:"token"`
+	Token          *string    `url:"token" json:"token"`
+	TokenExpiresAt *time.Time `url:"token_expires_at" json:"token_expires_at"`
 }
 
 // ResetRunnerAuthenticationToken resets a runner's authentication token.


Test patch:
diff --git a/fixtures_test.go b/fixtures_test.go
index c4fc5cb..38b8126 100644
--- a/fixtures_test.go
+++ b/fixtures_test.go
@@ -170,7 +170,8 @@ const (
 	// exampleRegisterNewRunner provides fixture for Runners tests.
 	exampleRegisterNewRunner = `{
 		"id": 12345,
-		"token": "6337ff461c94fd3fa32ba3b1ff4125"
+		"token": "6337ff461c94fd3fa32ba3b1ff4125",
+		"token_expires_at": "2016-01-25T16:39:48.166Z"
 	}`
 
 	// exampleReleaseLink provides fixture for Release Links tests.
diff --git a/runners_test.go b/runners_test.go
index 8eb59b3..27faf18 100644
--- a/runners_test.go
+++ b/runners_test.go
@@ -256,8 +256,9 @@ func TestRegisterNewRunner(t *testing.T) {
 	}
 
 	want := &Runner{
-		ID:    12345,
-		Token: "6337ff461c94fd3fa32ba3b1ff4125",
+		ID:             12345,
+		Token:          "6337ff461c94fd3fa32ba3b1ff4125",
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, runner) {
 		t.Errorf("Runners.RegisterNewRunner returned %+v, want %+v", runner, want)
@@ -286,7 +287,8 @@ func TestRegisterNewRunnerInfo(t *testing.T) {
 			"name": "some name",
 			"online": true,
 			"status": "online",
-			"token": "1111122222333333444444"
+			"token": "1111122222333333444444",
+			"token_expires_at": "2016-01-25T16:39:48.166Z"
 		  }`)
 	})
 
@@ -311,14 +313,15 @@ func TestRegisterNewRunnerInfo(t *testing.T) {
 	}
 
 	want := &Runner{
-		ID:          53,
-		Description: "some description",
-		Active:      true,
-		IPAddress:   "1.2.3.4",
-		Name:        "some name",
-		Online:      true,
-		Status:      "online",
-		Token:       "1111122222333333444444",
+		ID:             53,
+		Description:    "some description",
+		Active:         true,
+		IPAddress:      "1.2.3.4",
+		Name:           "some name",
+		Online:         true,
+		Status:         "online",
+		Token:          "1111122222333333444444",
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, runner) {
 		t.Errorf("Runners.RegisterNewRunner returned %+v, want %+v", runner, want)
@@ -404,7 +407,8 @@ func TestResetInstanceRunnerRegistrationToken(t *testing.T) {
 		testMethod(t, r, http.MethodPost)
 		w.WriteHeader(http.StatusCreated)
 		fmt.Fprint(w, `{
-			"token": "6337ff461c94fd3fa32ba3b1ff4125"
+			"token": "6337ff461c94fd3fa32ba3b1ff4125",
+			"token_expires_at": "2016-01-25T16:39:48.166Z"
 		}`)
 	})
 
@@ -414,7 +418,8 @@ func TestResetInstanceRunnerRegistrationToken(t *testing.T) {
 	}
 
 	want := &RunnerRegistrationToken{
-		Token: String("6337ff461c94fd3fa32ba3b1ff4125"),
+		Token:          String("6337ff461c94fd3fa32ba3b1ff4125"),
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, token) {
 		t.Errorf("Runners.ResetInstanceRunnerRegistrationToken returned %+v, want %+v", token, want)
@@ -434,7 +439,8 @@ func TestResetGroupRunnerRegistrationToken(t *testing.T) {
 		testMethod(t, r, http.MethodPost)
 		w.WriteHeader(http.StatusCreated)
 		fmt.Fprint(w, `{
-			"token": "6337ff461c94fd3fa32ba3b1ff4125"
+			"token": "6337ff461c94fd3fa32ba3b1ff4125",
+			"token_expires_at": "2016-01-25T16:39:48.166Z"
 		}`)
 	})
 
@@ -444,7 +450,8 @@ func TestResetGroupRunnerRegistrationToken(t *testing.T) {
 	}
 
 	want := &RunnerRegistrationToken{
-		Token: String("6337ff461c94fd3fa32ba3b1ff4125"),
+		Token:          String("6337ff461c94fd3fa32ba3b1ff4125"),
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, token) {
 		t.Errorf("Runners.ResetGroupRunnerRegistrationToken returned %+v, want %+v", token, want)
@@ -464,7 +471,8 @@ func TestResetProjectRunnerRegistrationToken(t *testing.T) {
 		testMethod(t, r, http.MethodPost)
 		w.WriteHeader(http.StatusCreated)
 		fmt.Fprint(w, `{
-			"token": "6337ff461c94fd3fa32ba3b1ff4125"
+			"token": "6337ff461c94fd3fa32ba3b1ff4125",
+			"token_expires_at": "2016-01-25T16:39:48.166Z"
 		}`)
 	})
 
@@ -474,7 +482,8 @@ func TestResetProjectRunnerRegistrationToken(t *testing.T) {
 	}
 
 	want := &RunnerRegistrationToken{
-		Token: String("6337ff461c94fd3fa32ba3b1ff4125"),
+		Token:          String("6337ff461c94fd3fa32ba3b1ff4125"),
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, token) {
 		t.Errorf("Runners.ResetProjectRunnerRegistrationToken returned %+v, want %+v", token, want)
@@ -494,7 +503,8 @@ func TestResetRunnerAuthenticationToken(t *testing.T) {
 		testMethod(t, r, http.MethodPost)
 		w.WriteHeader(http.StatusCreated)
 		fmt.Fprint(w, `{
-			"token": "6337ff461c94fd3fa32ba3b1ff4125"
+			"token": "6337ff461c94fd3fa32ba3b1ff4125",
+			"token_expires_at": "2016-01-25T16:39:48.166Z"
 		}`)
 	})
 
@@ -504,7 +514,8 @@ func TestResetRunnerAuthenticationToken(t *testing.T) {
 	}
 
 	want := &RunnerAuthenticationToken{
-		Token: String("6337ff461c94fd3fa32ba3b1ff4125"),
+		Token:          String("6337ff461c94fd3fa32ba3b1ff4125"),
+		TokenExpiresAt: Time(time.Date(2016, time.January, 25, 16, 39, 48, 166000000, time.UTC)),
 	}
 	if !reflect.DeepEqual(want, token) {
 		t.Errorf("Runners.ResetRunnerAuthenticationToken returned %+v, want %+v", token, want)