From 75ad5f4a64f565b47162a3758eb6a33b1ef1bf3c Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Tue, 5 Nov 2024 16:58:29 +0100 Subject: [PATCH] Fix the expires_at type --- deploy_keys.go | 8 ++++---- deploy_keys_test.go | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/deploy_keys.go b/deploy_keys.go index 429200302..8834edbc4 100644 --- a/deploy_keys.go +++ b/deploy_keys.go @@ -165,10 +165,10 @@ func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int, options // GitLab API docs: // https://docs.gitlab.com/ee/api/deploy_keys.html#add-deploy-key-for-a-project type AddDeployKeyOptions struct { - Key *string `url:"key,omitempty" json:"key,omitempty"` - Title *string `url:"title,omitempty" json:"title,omitempty"` - CanPush *bool `url:"can_push,omitempty" json:"can_push,omitempty"` - ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"` + Key *string `url:"key,omitempty" json:"key,omitempty"` + Title *string `url:"title,omitempty" json:"title,omitempty"` + CanPush *bool `url:"can_push,omitempty" json:"can_push,omitempty"` + ExpiresAt *time.Time `url:"expires_at,omitempty" json:"expires_at,omitempty"` } // AddDeployKey creates a new deploy key for a project. If deploy key already diff --git a/deploy_keys_test.go b/deploy_keys_test.go index 56d97b4a9..d760bc6d1 100644 --- a/deploy_keys_test.go +++ b/deploy_keys_test.go @@ -272,13 +272,16 @@ func TestAddDeployKey_withExpiresAt(t *testing.T) { }`) }) - expiresAtIsoTime := ISOTime(time.Date(2999, time.March, 1, 0, 0, 0, 0, time.UTC)) + expiresAt, err := time.Parse(timeLayout, "2999-03-01T00:00:00.000Z") + if err != nil { + t.Errorf("DeployKeys.AddDeployKey returned an error while parsing time: %v", err) + } opt := &AddDeployKeyOptions{ Key: Ptr("ssh-rsa AAAA..."), Title: Ptr("My deploy key"), CanPush: Ptr(true), - ExpiresAt: &expiresAtIsoTime, + ExpiresAt: &expiresAt, } deployKey, _, err := client.DeployKeys.AddDeployKey(5, opt) if err != nil { @@ -287,12 +290,7 @@ func TestAddDeployKey_withExpiresAt(t *testing.T) { createdAt, err := time.Parse(timeLayout, "2015-08-29T12:44:31.550Z") if err != nil { - t.Errorf("DeployKeys.ListAllDeployKeys returned an error while parsing time: %v", err) - } - - expiresAt, err := time.Parse(timeLayout, "2999-03-01T00:00:00.000Z") - if err != nil { - t.Errorf("DeployKeys.ListAllDeployKeys returned an error while parsing time: %v", err) + t.Errorf("DeployKeys.AddDeployKey returned an error while parsing time: %v", err) } want := &ProjectDeployKey{