Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
lourens-octopus committed Dec 5, 2024
1 parent de5bb07 commit 2f7269e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion octopusdeploy_framework/resource_git_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func (r *gitTriggerResource) Delete(ctx context.Context, req resource.DeleteRequ
client := r.Config.Client

if err := client.ProjectTriggers.DeleteByID(data.ID.ValueString()); err != nil {
resp.Diagnostics.AddError("unable to delete Git Trigger", err.Error())
summary := fmt.Sprintf("unable to delete Git Trigger '%s'", client.GetSpaceID())
resp.Diagnostics.AddError(summary, err.Error())
return
}
}
Expand Down
23 changes: 21 additions & 2 deletions octopusdeploy_framework/resource_git_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func testAssertGitTriggerAttributes(expected gitTriggerTestData, prefix string)
resource.TestCheckResourceAttr(prefix, "project_id", expected.projectId),
resource.TestCheckResourceAttr(prefix, "channel_id", expected.channelId),
resource.TestCheckResourceAttr(prefix, "is_disabled", strconv.FormatBool(expected.isDisabled)),
resource.TestCheckResourceAttr(prefix, "sources", convertGitTriggerSourcesToString(expected.sources)),
resource.TestCheckResourceAttr(prefix, "sources.0.deploymentActionSlug", expected.sources[0].deploymentActionSlug),
)
}

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

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

Expand All @@ -212,6 +212,25 @@ func convertGitTriggerSourcesToString(sources []gitTriggerSourcesTestData) strin
return result
}

func convertGitTriggerSourceToString(source gitTriggerSourcesTestData) string {
var result string

result += fmt.Sprintf(`
{
deployment_action_slug = "%s"
git_dependency_name = "%s"
include_file_paths = [%s]
exclude_file_paths = [%s]
}`,
source.deploymentActionSlug,
source.gitDependencyName,
convertStringSliceToString(source.includeFilePaths),
convertStringSliceToString(source.excludeFilePaths),
)

return result
}

func convertStringSliceToString(slice []string) string {
return fmt.Sprintf(`"%s"`, strings.Join(slice, `", "`))
}

0 comments on commit 2f7269e

Please sign in to comment.