Skip to content

Commit

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

client := r.Config.Client

if err := client.ProjectTriggers.DeleteByID(data.ID.ValueString()); err != nil {
project := projects.NewProject(data.ProjectId.ValueString(), data.SpaceId.ValueString(), "")
projectTrigger := triggers.NewProjectTrigger(data.Name.ValueString(), data.Description.ValueString(), data.IsDisabled.ValueBool(), project, nil, nil)
projectTrigger.ID = data.ID.ValueString()

if err := client.ProjectTriggers.Delete(projectTrigger); err != nil {
resp.Diagnostics.AddError("unable to delete Git Trigger", err.Error())
return
}
Expand Down
36 changes: 30 additions & 6 deletions octopusdeploy_framework/resource_git_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"path/filepath"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -56,9 +57,9 @@ func TestAccOctopusDeployGitTrigger(t *testing.T) {
updateData := gitTriggerTestData{
name: createData.name + "-updated",
description: createData.description + "-updated",
projectId: createData.projectId + "-updated",
channelId: createData.channelId + "-updated",
spaceId: createData.spaceId + "-updated",
projectId: createData.projectId,
channelId: createData.channelId,
spaceId: createData.spaceId,
isDisabled: true,
sources: []gitTriggerSourcesTestData{
{
Expand Down Expand Up @@ -89,13 +90,17 @@ func TestAccOctopusDeployGitTrigger(t *testing.T) {

func setupTestSpace(t *testing.T) (string, string, string, string) {
testFramework := test.OctopusContainerTest{}
newSpaceId, err := testFramework.Act(t, octoContainer, "../terraform", "45a-projectwithgitdependency", []string{})
//newSpaceId, err := testFramework.Act(t, octoContainer, "../terraform", "45a-projectwithgitdependency", []string{})
err := testFramework.TerraformInitAndApply(t, octoContainer, filepath.Join("../terraform", "45a-projectwithgitdependency"), "Spaces-1", []string{})

if err != nil {
t.Fatal(err.Error())
}

newSpaceId := "Spaces-1"

client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, test.ApiKey)

query := projects.ProjectsQuery{
PartialName: "Test",
Skip: 0,
Expand Down Expand Up @@ -174,7 +179,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 +191,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 +217,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 6bad381

Please sign in to comment.