@@ -2,6 +2,7 @@ package gitlab
22
33import (
44 "fmt"
5+ "net/http"
56 "strconv"
67 "testing"
78
@@ -88,6 +89,7 @@ func testAccCheckGitlabDeployTokenAttributes(deployToken *gitlab.DeployToken, wa
8889 return fmt .Errorf ("got name %q; want %q" , deployToken .Name , want .Name )
8990 }
9091
92+ // TODO Uncomment once this bug is fixed https://gitlab.com/gitlab-org/gitlab/-/issues/211963
9193 // if deployToken.Username != want.Username {
9294 // return fmt.Errorf("got username %q; want %q", deployToken.Username, want.Username)
9395 // }
@@ -113,23 +115,27 @@ func testAccCheckGitlabDeployTokenDestroy(s *terraform.State) error {
113115 group := rs .Primary .Attributes ["group" ]
114116
115117 var gotDeployTokens []* gitlab.DeployToken
118+ var resp * gitlab.Response
116119
117120 if project != "" {
118- gotDeployTokens , _ , err = conn .DeployTokens .ListProjectDeployTokens (project , nil )
121+ gotDeployTokens , resp , err = conn .DeployTokens .ListProjectDeployTokens (project , nil )
119122 } else if group != "" {
120- gotDeployTokens , _ , err = conn .DeployTokens .ListGroupDeployTokens (group , nil )
123+ gotDeployTokens , resp , err = conn .DeployTokens .ListGroupDeployTokens (group , nil )
121124 } else {
122- return fmt .Errorf ("Somehow neither project nor group were set" )
123- }
124- if err != nil {
125- return err
125+ return fmt .Errorf ("somehow neither project nor group were set" )
126126 }
127127
128- for _ , token := range gotDeployTokens {
129- if token .ID == deployTokenID {
130- return fmt .Errorf ("Deploy token still exists" )
128+ if err == nil {
129+ for _ , token := range gotDeployTokens {
130+ if token .ID == deployTokenID {
131+ return fmt .Errorf ("Deploy token still exists" )
132+ }
131133 }
132134 }
135+
136+ if resp .StatusCode != http .StatusNotFound {
137+ return err
138+ }
133139 }
134140
135141 return nil
@@ -149,7 +155,10 @@ resource "gitlab_project" "foo" {
149155resource "gitlab_deploy_token" "foo" {
150156 project = "${gitlab_project.foo.id}"
151157 name = "deployToken-%d"
152- username = "my-username"
158+ # TODO Uncomment once this bug is fixed https://gitlab.com/gitlab-org/gitlab/-/issues/211963
159+ # username = "my-username"
160+
161+ expires_at = "2021-03-14T07:20:50Z"
153162
154163 scopes = [
155164 "read_registry",
0 commit comments