Skip to content

Commit

Permalink
added update test to project freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Nov 24, 2024
1 parent c761241 commit 1aa7b68
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions octopusdeploy_framework/resource_deploymentfreeze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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"
"strings"
"testing"
"time"
)
Expand All @@ -17,7 +18,8 @@ func TestNewDeploymentFreezeResource(t *testing.T) {
start := fmt.Sprintf("%d-11-21T06:30:00+10:00", time.Now().Year()+1)
end := fmt.Sprintf("%d-11-21T08:30:00+10:00", time.Now().Year()+1)
projectName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
environmentName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
environmentName1 := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
environmentName2 := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
spaceName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
projectGroupName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
lifecycleName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
Expand All @@ -33,22 +35,44 @@ func TestNewDeploymentFreezeResource(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "start", start),
resource.TestCheckResourceAttr(resourceName, "end", end)),
Config: testDeploymentFreezeBasic(localName, name, start, end, spaceName, environmentName, projectName, projectGroupName, lifecycleName),
Config: testDeploymentFreezeBasic(localName, name, start, end, spaceName, []string{environmentName1}, projectName, projectGroupName, lifecycleName),
},
},
})

resource.Test(t, resource.TestCase{
CheckDestroy: testDeploymentFreezeCheckDestroy,
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Check: resource.ComposeTestCheckFunc(
testDeploymentFreezeExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "start", start),
resource.TestCheckResourceAttr(resourceName, "end", end)),
Config: testDeploymentFreezeBasic(localName, name, start, end, spaceName, []string{environmentName1, environmentName2}, projectName, projectGroupName, lifecycleName),
},
},
})
}

func testDeploymentFreezeBasic(localName string, freezeName string, start string, end string, spaceName string, environmentName string, projectName string, projectGroupName string, lifecycleName string) string {
func testDeploymentFreezeBasic(localName string, freezeName string, start string, end string, spaceName string, environments []string, projectName string, projectGroupName string, lifecycleName string) string {
spaceLocalName := fmt.Sprintf("space_%s", localName)
environmentLocalName := fmt.Sprintf("environment_%s", localName)
projectLocalName := fmt.Sprintf("project_%s", localName)
lifecycleLocalName := fmt.Sprintf("lifecycle_%s", localName)
projectGroupLocalName := fmt.Sprintf("project_group_%s", localName)
environmentScopes := make([]string, 0, len(environments))
environmentResources := ""
for i, environmentName := range environments {
environmentLocalName := fmt.Sprintf("environment_%d_%s", i, localName)
environmentResources += fmt.Sprintln(createEnvironment(spaceLocalName, environmentLocalName, environmentName))
environmentScopes = append(environmentScopes, fmt.Sprintf("resource.octopusdeploy_environment.%s.id", environmentLocalName))
}

projectScopes := fmt.Sprintf(`{
"${resource.octopusdeploy_project.%s.id}" = [ resource.octopusdeploy_environment.%s.id
}`, projectLocalName, environmentLocalName)
"${resource.octopusdeploy_project.%s.id}" = [ %s ]
}`, projectLocalName, strings.Join(environmentScopes, ","))

return fmt.Sprintf(`
%s
Expand All @@ -69,7 +93,7 @@ func testDeploymentFreezeBasic(localName string, freezeName string, start string
%s
}`,
createSpace(spaceLocalName, spaceName),
createEnvironment(spaceLocalName, environmentLocalName, environmentName),
environmentResources,
createLifecycle(spaceLocalName, lifecycleLocalName, lifecycleName),
createProjectGroup(spaceLocalName, projectGroupLocalName, projectGroupName),
createProject(spaceLocalName, projectLocalName, projectName, lifecycleLocalName, projectGroupLocalName),
Expand Down

0 comments on commit 1aa7b68

Please sign in to comment.