@@ -2,6 +2,7 @@ package gitlab
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
5
6
"strconv"
6
7
"testing"
7
8
@@ -88,6 +89,7 @@ func testAccCheckGitlabDeployTokenAttributes(deployToken *gitlab.DeployToken, wa
88
89
return fmt .Errorf ("got name %q; want %q" , deployToken .Name , want .Name )
89
90
}
90
91
92
+ // TODO Uncomment once this bug is fixed https://gitlab.com/gitlab-org/gitlab/-/issues/211963
91
93
// if deployToken.Username != want.Username {
92
94
// return fmt.Errorf("got username %q; want %q", deployToken.Username, want.Username)
93
95
// }
@@ -113,23 +115,27 @@ func testAccCheckGitlabDeployTokenDestroy(s *terraform.State) error {
113
115
group := rs .Primary .Attributes ["group" ]
114
116
115
117
var gotDeployTokens []* gitlab.DeployToken
118
+ var resp * gitlab.Response
116
119
117
120
if project != "" {
118
- gotDeployTokens , _ , err = conn .DeployTokens .ListProjectDeployTokens (project , nil )
121
+ gotDeployTokens , resp , err = conn .DeployTokens .ListProjectDeployTokens (project , nil )
119
122
} else if group != "" {
120
- gotDeployTokens , _ , err = conn .DeployTokens .ListGroupDeployTokens (group , nil )
123
+ gotDeployTokens , resp , err = conn .DeployTokens .ListGroupDeployTokens (group , nil )
121
124
} 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" )
126
126
}
127
127
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
+ }
131
133
}
132
134
}
135
+
136
+ if resp .StatusCode != http .StatusNotFound {
137
+ return err
138
+ }
133
139
}
134
140
135
141
return nil
@@ -149,7 +155,10 @@ resource "gitlab_project" "foo" {
149
155
resource "gitlab_deploy_token" "foo" {
150
156
project = "${gitlab_project.foo.id}"
151
157
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"
153
162
154
163
scopes = [
155
164
"read_registry",
0 commit comments