Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f85efe1

Browse files
test
1 parent de5bb07 commit f85efe1

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

octopusdeploy_framework/resource_git_trigger.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ func (r *gitTriggerResource) Delete(ctx context.Context, req resource.DeleteRequ
162162

163163
client := r.Config.Client
164164

165-
if err := client.ProjectTriggers.DeleteByID(data.ID.ValueString()); err != nil {
165+
project := projects.NewProject(data.ProjectId.ValueString(), data.SpaceId.ValueString(), "")
166+
projectTrigger := triggers.NewProjectTrigger(data.Name.ValueString(), data.Description.ValueString(), data.IsDisabled.ValueBool(), project, nil, nil)
167+
projectTrigger.ID = data.ID.ValueString()
168+
169+
if err := client.ProjectTriggers.Delete(projectTrigger); err != nil {
166170
resp.Diagnostics.AddError("unable to delete Git Trigger", err.Error())
167171
return
168172
}

octopusdeploy_framework/resource_git_trigger_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func TestAccOctopusDeployGitTrigger(t *testing.T) {
5656
updateData := gitTriggerTestData{
5757
name: createData.name + "-updated",
5858
description: createData.description + "-updated",
59-
projectId: createData.projectId + "-updated",
60-
channelId: createData.channelId + "-updated",
61-
spaceId: createData.spaceId + "-updated",
59+
projectId: createData.projectId,
60+
channelId: createData.channelId,
61+
spaceId: createData.spaceId,
6262
isDisabled: true,
6363
sources: []gitTriggerSourcesTestData{
6464
{
@@ -174,7 +174,7 @@ func testAssertGitTriggerAttributes(expected gitTriggerTestData, prefix string)
174174
resource.TestCheckResourceAttr(prefix, "project_id", expected.projectId),
175175
resource.TestCheckResourceAttr(prefix, "channel_id", expected.channelId),
176176
resource.TestCheckResourceAttr(prefix, "is_disabled", strconv.FormatBool(expected.isDisabled)),
177-
resource.TestCheckResourceAttr(prefix, "sources", convertGitTriggerSourcesToString(expected.sources)),
177+
//resource.TestCheckResourceAttr(prefix, "sources.0.deploymentActionSlug", expected.sources[0].deploymentActionSlug),
178178
)
179179
}
180180

@@ -186,7 +186,7 @@ func testGitTriggerCheckDestroy(s *terraform.State) error {
186186

187187
projectTrigger, err := octoClient.ProjectTriggers.GetByID(rs.Primary.ID)
188188
if err == nil && projectTrigger != nil {
189-
return fmt.Errorf("azure container registry feed (%s) still exists", rs.Primary.ID)
189+
return fmt.Errorf("git trigger (%s) still exists", rs.Primary.ID)
190190
}
191191
}
192192

@@ -212,6 +212,25 @@ func convertGitTriggerSourcesToString(sources []gitTriggerSourcesTestData) strin
212212
return result
213213
}
214214

215+
func convertGitTriggerSourceToString(source gitTriggerSourcesTestData) string {
216+
var result string
217+
218+
result += fmt.Sprintf(`
219+
{
220+
deployment_action_slug = "%s"
221+
git_dependency_name = "%s"
222+
include_file_paths = [%s]
223+
exclude_file_paths = [%s]
224+
}`,
225+
source.deploymentActionSlug,
226+
source.gitDependencyName,
227+
convertStringSliceToString(source.includeFilePaths),
228+
convertStringSliceToString(source.excludeFilePaths),
229+
)
230+
231+
return result
232+
}
233+
215234
func convertStringSliceToString(slice []string) string {
216235
return fmt.Sprintf(`"%s"`, strings.Join(slice, `", "`))
217236
}

0 commit comments

Comments
 (0)