Skip to content

Commit

Permalink
Remove hard-coded ProjectGroupIds from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-french committed Apr 18, 2019
1 parent 9aee821 commit 7449339
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions octopusdeploy/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ func TestAccOctopusDeployProjectBasic(t *testing.T) {
const terraformNamePrefix = "octopusdeploy_project.foo"
const projectName = "Funky Monkey"
const lifeCycleID = "Lifecycles-1"
const projectGroupID = "ProjectGroups-1"
const allowDeploymentsToNoTargets = "true"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOctopusDeployProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccProjectBasic(projectName, lifeCycleID, projectGroupID, allowDeploymentsToNoTargets),
Config: testAccProjectBasic(projectName, lifeCycleID, allowDeploymentsToNoTargets),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployProjectExists(terraformNamePrefix),
resource.TestCheckResourceAttr(
terraformNamePrefix, "name", projectName),
resource.TestCheckResourceAttr(
terraformNamePrefix, "lifecycle_id", lifeCycleID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "project_group_id", projectGroupID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "allow_deployments_to_no_targets", allowDeploymentsToNoTargets),
),
Expand All @@ -44,7 +41,6 @@ func TestAccOctopusDeployProjectWithDeploymentStepWindowsService(t *testing.T) {
const terraformNamePrefix = "octopusdeploy_project.foo"
const projectName = "Funky Monkey"
const lifeCycleID = "Lifecycles-1"
const projectGroupID = "ProjectGroups-1"
const serviceName = "Epic Service"
const executablePath = `bin\\MyService.exe` // needs 4 slashes to appear in the TF config as a double slash
const stepName = "Deploying Epic Service"
Expand All @@ -59,7 +55,7 @@ func TestAccOctopusDeployProjectWithDeploymentStepWindowsService(t *testing.T) {
CheckDestroy: testAccCheckOctopusDeployProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccWithDeploymentStepWindowsService(projectName, lifeCycleID, projectGroupID, serviceName, executablePath, stepName, packageName, targetRoles),
Config: testAccWithDeploymentStepWindowsService(projectName, lifeCycleID, serviceName, executablePath, stepName, packageName, targetRoles),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployProjectExists(terraformNamePrefix),
resource.TestMatchResourceAttr(
Expand All @@ -68,8 +64,6 @@ func TestAccOctopusDeployProjectWithDeploymentStepWindowsService(t *testing.T) {
terraformNamePrefix, "name", projectName),
resource.TestCheckResourceAttr(
terraformNamePrefix, "lifecycle_id", lifeCycleID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "project_group_id", projectGroupID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "deployment_step_windows_service.0.service_name", serviceName),
resource.TestCheckResourceAttr(
Expand All @@ -92,8 +86,6 @@ func TestAccOctopusDeployProjectWithUpdate(t *testing.T) {
const terraformNamePrefix = "octopusdeploy_project.foo"
const projectName = "Funky Monkey"
const lifeCycleID = "Lifecycles-1"
const projectGroupID = "ProjectGroups-1"
const description = "I am a new description"
const allowDeploymentsToNoTargets = "true"
inlineScriptRegex := regexp.MustCompile(".*Get\\-Process.*")
resource.Test(t, resource.TestCase{
Expand All @@ -103,15 +95,13 @@ func TestAccOctopusDeployProjectWithUpdate(t *testing.T) {
Steps: []resource.TestStep{
// create project with no description
{
Config: testAccProjectBasic(projectName, lifeCycleID, projectGroupID, allowDeploymentsToNoTargets),
Config: testAccProjectBasic(projectName, lifeCycleID, allowDeploymentsToNoTargets),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployProjectExists(terraformNamePrefix),
resource.TestCheckResourceAttr(
terraformNamePrefix, "name", projectName),
resource.TestCheckResourceAttr(
terraformNamePrefix, "lifecycle_id", lifeCycleID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "project_group_id", projectGroupID),
),
},
// create update it with a description + build steps
Expand All @@ -123,8 +113,6 @@ func TestAccOctopusDeployProjectWithUpdate(t *testing.T) {
terraformNamePrefix, "name", "Project Name"),
resource.TestCheckResourceAttr(
terraformNamePrefix, "lifecycle_id", "Lifecycles-1"),
resource.TestCheckResourceAttr(
terraformNamePrefix, "project_group_id", "ProjectGroups-1"),
resource.TestCheckResourceAttr(
terraformNamePrefix, "description", "My Awesome Description"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -201,15 +189,13 @@ func TestAccOctopusDeployProjectWithUpdate(t *testing.T) {
},
// update again by remove its description
{
Config: testAccProjectBasic(projectName, lifeCycleID, projectGroupID, allowDeploymentsToNoTargets),
Config: testAccProjectBasic(projectName, lifeCycleID, allowDeploymentsToNoTargets),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployProjectExists(terraformNamePrefix),
resource.TestCheckResourceAttr(
terraformNamePrefix, "name", projectName),
resource.TestCheckResourceAttr(
terraformNamePrefix, "lifecycle_id", lifeCycleID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "project_group_id", projectGroupID),
resource.TestCheckResourceAttr(
terraformNamePrefix, "description", ""),
resource.TestCheckNoResourceAttr(
Expand All @@ -224,7 +210,7 @@ func TestAccOctopusDeployProjectWithUpdate(t *testing.T) {
})
}

func testAccProjectBasic(name, lifeCycleID, projectGroupID string, allowDeploymentsToNoTargets string) string {
func testAccProjectBasic(name, lifeCycleID, allowDeploymentsToNoTargets string) string {
return fmt.Sprintf(`
resource "octopusdeploy_project_group" "foo" {
name = "Integration Test Project Group"
Expand All @@ -233,11 +219,11 @@ func testAccProjectBasic(name, lifeCycleID, projectGroupID string, allowDeployme
resource "octopusdeploy_project" "foo" {
name = "%s"
lifecycle_id = "%s"
project_group_id = "%s"
project_group_id = "${octopusdeploy_project_group.foo.id}"
allow_deployments_to_no_targets = "%s"
}
`,
name, lifeCycleID, projectGroupID, allowDeploymentsToNoTargets,
name, lifeCycleID, allowDeploymentsToNoTargets,
)
}

Expand Down Expand Up @@ -327,12 +313,17 @@ resource "octopusdeploy_project" "foo" {
}
`

func testAccWithDeploymentStepWindowsService(name, lifeCycleID, projectGroupID, serviceName, executablePath, stepName, packageName string, targetRoles []string) string {
func testAccWithDeploymentStepWindowsService(name, lifeCycleID, serviceName, executablePath, stepName, packageName string, targetRoles []string) string {
return fmt.Sprintf(`
resource "octopusdeploy_project_group" "foo" {
name = "Integration Test Project Group"
}
resource "octopusdeploy_project" "foo" {
name = "%s"
lifecycle_id = "%s"
project_group_id = "%s"
project_group_id = "${octopusdeploy_project_group.foo.id}"
deployment_step_windows_service {
executable_path = "%s"
Expand All @@ -346,7 +337,7 @@ func testAccWithDeploymentStepWindowsService(name, lifeCycleID, projectGroupID,
}
}
`,
name, lifeCycleID, projectGroupID, executablePath, serviceName, stepName, packageName, strings.Join(targetRoles, "\",\""),
name, lifeCycleID, executablePath, serviceName, stepName, packageName, strings.Join(targetRoles, "\",\""),
)
}

Expand Down

0 comments on commit 7449339

Please sign in to comment.