Skip to content

Commit 3977a55

Browse files
authored
Merge pull request #1160 from timofurrer/testing/destroy-checks
Refactor destory checks to check for resource under test
2 parents becf2ce + 221f6de commit 3977a55

5 files changed

+34
-35
lines changed

internal/provider/resource_gitlab_label_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,16 @@ func testAccCheckGitlabLabelAttributes(label *gitlab.Label, want *testAccGitlabL
141141

142142
func testAccCheckGitlabLabelDestroy(s *terraform.State) error {
143143
for _, rs := range s.RootModule().Resources {
144-
if rs.Type != "gitlab_project" {
144+
if rs.Type != "gitlab_label" {
145145
continue
146146
}
147147

148-
gotRepo, _, err := testGitlabClient.Projects.GetProject(rs.Primary.ID, nil)
148+
project := rs.Primary.Attributes["project"]
149+
labelName := rs.Primary.ID
150+
151+
_, _, err := testGitlabClient.Labels.GetLabel(project, labelName)
149152
if err == nil {
150-
if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
151-
if gotRepo.MarkedForDeletionAt == nil {
152-
return fmt.Errorf("Repository still exists")
153-
}
154-
}
153+
return fmt.Errorf("Label %s in project %s still exists", labelName, project)
155154
}
156155
if !is404(err) {
157156
return err

internal/provider/resource_gitlab_pipeline_trigger_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@ func testAccCheckGitlabPipelineTriggerAttributes(trigger *gitlab.PipelineTrigger
140140

141141
func testAccCheckGitlabPipelineTriggerDestroy(s *terraform.State) error {
142142
for _, rs := range s.RootModule().Resources {
143-
if rs.Type != "gitlab_project" {
143+
if rs.Type != "gitlab_pipeline_trigger" {
144144
continue
145145
}
146146

147-
gotRepo, _, err := testGitlabClient.Projects.GetProject(rs.Primary.ID, nil)
147+
project := rs.Primary.Attributes["project"]
148+
pipelineTriggerID, err := strconv.Atoi(rs.Primary.ID)
149+
if err != nil {
150+
return err
151+
}
152+
153+
_, _, err = testGitlabClient.PipelineTriggers.GetPipelineTrigger(project, pipelineTriggerID)
148154
if err == nil {
149-
if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
150-
if gotRepo.MarkedForDeletionAt == nil {
151-
return fmt.Errorf("Repository still exists")
152-
}
153-
}
155+
return fmt.Errorf("Pipeline Trigger %d in project %s still exists", pipelineTriggerID, project)
154156
}
155157
if !is404(err) {
156158
return err

internal/provider/resource_gitlab_project_hook_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,19 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
193193

194194
func testAccCheckGitlabProjectHookDestroy(s *terraform.State) error {
195195
for _, rs := range s.RootModule().Resources {
196-
if rs.Type != "gitlab_project" {
196+
if rs.Type != "gitlab_project_hook" {
197197
continue
198198
}
199199

200-
gotRepo, _, err := testGitlabClient.Projects.GetProject(rs.Primary.ID, nil)
200+
project := rs.Primary.Attributes["project"]
201+
hookID, err := strconv.Atoi(rs.Primary.ID)
202+
if err != nil {
203+
return err
204+
}
205+
206+
_, _, err = testGitlabClient.Projects.GetProjectHook(project, hookID)
201207
if err == nil {
202-
if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
203-
if gotRepo.MarkedForDeletionAt == nil {
204-
return fmt.Errorf("Repository still exists")
205-
}
206-
}
208+
return fmt.Errorf("Project Hook %d in project %s still exists", hookID, project)
207209
}
208210
if !is404(err) {
209211
return err

internal/provider/resource_gitlab_service_jira_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,15 @@ func testAccCheckGitlabServiceJiraExists(n string, service *gitlab.JiraService)
121121

122122
func testAccCheckGitlabServiceJiraDestroy(s *terraform.State) error {
123123
for _, rs := range s.RootModule().Resources {
124-
if rs.Type != "gitlab_project" {
124+
if rs.Type != "gitlab_service_jira" {
125125
continue
126126
}
127127

128-
gotRepo, _, err := testGitlabClient.Projects.GetProject(rs.Primary.ID, nil)
128+
project := rs.Primary.ID
129+
130+
_, _, err := testGitlabClient.Services.GetJiraService(project)
129131
if err == nil {
130-
if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
131-
if gotRepo.MarkedForDeletionAt == nil {
132-
return fmt.Errorf("Repository still exists")
133-
}
134-
}
132+
return fmt.Errorf("Jira Service Integration in project %s still exists", project)
135133
}
136134
if !is404(err) {
137135
return err

internal/provider/resource_gitlab_service_slack_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,15 @@ func testAccCheckGitlabServiceExists(n string, service *gitlab.SlackService) res
155155

156156
func testAccCheckGitlabServiceSlackDestroy(s *terraform.State) error {
157157
for _, rs := range s.RootModule().Resources {
158-
if rs.Type != "gitlab_project" {
158+
if rs.Type != "gitlab_service_slack" {
159159
continue
160160
}
161161

162-
gotRepo, _, err := testGitlabClient.Projects.GetProject(rs.Primary.ID, nil)
162+
project := rs.Primary.ID
163+
164+
_, _, err := testGitlabClient.Services.GetSlackService(project)
163165
if err == nil {
164-
if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
165-
if gotRepo.MarkedForDeletionAt == nil {
166-
return fmt.Errorf("Repository still exists")
167-
}
168-
}
166+
return fmt.Errorf("Slack Service Integration in project %s still exists", project)
169167
}
170168
if !is404(err) {
171169
return err

0 commit comments

Comments
 (0)