Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbristowe committed Dec 15, 2020
1 parent 04b59dd commit 354c33f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 75 deletions.
2 changes: 1 addition & 1 deletion octopusdeploy/apply_terraform_action_test.go
Expand Up @@ -16,10 +16,10 @@ func TestAccOctopusDeployApplyTerraformAction(t *testing.T) {
CheckDestroy: testAccCheckOctopusDeployDeploymentProcessDestroy,
Steps: []resource.TestStep{
{
Config: testAccApplyTerraformAction(),
Check: resource.ComposeTestCheckFunc(
testAccCheckApplyTerraformAction(),
),
Config: testAccApplyTerraformAction(),
},
},
})
Expand Down
54 changes: 18 additions & 36 deletions octopusdeploy/deployment_process_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand All @@ -16,33 +17,25 @@ func TestAccOctopusDeployDeploymentProcessBasic(t *testing.T) {
CheckDestroy: testAccCheckOctopusDeployDeploymentProcessDestroy,
Steps: []resource.TestStep{
{
Config: testAccDeploymentProcessBasic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployDeploymentProcess(),
),
Config: testAccDeploymentProcessBasic(),
},
},
})
}

func testAccDeploymentProcessBasic() string {
return `
resource "octopusdeploy_lifecycle" "test" {
name = "Test Lifecycle"
}
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
description := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

resource "octopusdeploy_project_group" "test" {
name = "Test Group"
}
resource "octopusdeploy_project" "test" {
name = "Test Project"
lifecycle_id = "${octopusdeploy_lifecycle.test.id}"
project_group_id = "${octopusdeploy_project_group.test.id}"
}
projectID := "octopusdeploy_project." + localName + ".id"

resource "octopusdeploy_deployment_process" "test" {
project_id = "${octopusdeploy_project.test.id}"
return fmt.Sprintf(testAccProjectBasic(localName, name, description)+"\n"+
`resource "octopusdeploy_deployment_process" "test" {
project_id = %s
step {
name = "Test"
Expand All @@ -52,7 +45,6 @@ func testAccDeploymentProcessBasic() string {
condition_expression = "#{run}"
start_trigger = "StartWithPrevious"
window_size = "5"
action {
name = "Test"
Expand Down Expand Up @@ -126,37 +118,27 @@ func testAccDeploymentProcessBasic() string {
}
}
}
}
`
}`, projectID)
}

func testAccBuildTestAction(action string) string {
return fmt.Sprintf(`
resource "octopusdeploy_lifecycle" "test" {
name = "Test Lifecycle"
}
resource "octopusdeploy_project_group" "test" {
name = "Test Group"
}
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
description := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)

resource "octopusdeploy_project" "test" {
name = "Test Project"
lifecycle_id = "${octopusdeploy_lifecycle.test.id}"
project_group_id = "${octopusdeploy_project_group.test.id}"
}
projectID := "octopusdeploy_project." + localName + ".id"

resource "octopusdeploy_deployment_process" "test" {
project_id = "${octopusdeploy_project.test.id}"
return fmt.Sprintf(testAccProjectBasic(localName, name, description)+"\n"+
`resource "octopusdeploy_deployment_process" "test" {
project_id = %s
step {
name = "Test"
target_roles = ["WebServer"]
%s
}
}
`, action)
}`, projectID, action)
}

func testAccCheckOctopusDeployDeploymentProcessDestroy(s *terraform.State) error {
Expand Down
18 changes: 9 additions & 9 deletions octopusdeploy/resource_account_test.go
Expand Up @@ -18,7 +18,7 @@ func TestAccAccountBasic(t *testing.T) {

accessKey := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
accountType := octopusdeploy.AccountTypeAzureServicePrincipal
clientID := uuid.New()
applicationID := uuid.New()
clientSecret := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
secretKey := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
Expand All @@ -35,14 +35,14 @@ func TestAccAccountBasic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccAccountExists(prefix),
resource.TestCheckResourceAttr(prefix, "account_type", string(accountType)),
resource.TestCheckResourceAttr(prefix, "client_id", clientID.String()),
resource.TestCheckResourceAttr(prefix, "application_id", applicationID.String()),
resource.TestCheckResourceAttr(prefix, "client_secret", clientSecret),
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "subscription_id", subscriptionID.String()),
resource.TestCheckResourceAttr(prefix, "tenant_id", tenantID.String()),
resource.TestCheckResourceAttr(prefix, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
),
Config: testAccountBasic(localName, name, accountType, clientID, tenantID, subscriptionID, clientSecret, accessKey, secretKey, tenantedDeploymentMode),
Config: testAccountBasic(localName, name, accountType, applicationID, tenantID, subscriptionID, clientSecret, accessKey, secretKey, tenantedDeploymentMode),
},
},
})
Expand All @@ -54,7 +54,7 @@ func TestAccOctopusCloudTest(t *testing.T) {

accessKey := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
accountType := octopusdeploy.AccountTypeAzureServicePrincipal
clientID := uuid.New()
applicationID := uuid.New()
clientSecret := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := "Principal"
secretKey := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
Expand All @@ -71,29 +71,29 @@ func TestAccOctopusCloudTest(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccAccountExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "account_type", string(accountType)),
resource.TestCheckResourceAttr(resourceName, "client_id", clientID.String()),
resource.TestCheckResourceAttr(resourceName, "client_id", applicationID.String()),
resource.TestCheckResourceAttr(resourceName, "client_secret", clientSecret),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "subscription_id", subscriptionID.String()),
resource.TestCheckResourceAttr(resourceName, "tenant_id", tenantID.String()),
resource.TestCheckResourceAttr(resourceName, "tenanted_deployment_participation", string(tenantedDeploymentMode)),
),
Config: testAccountBasic(localName, name, accountType, clientID, tenantID, subscriptionID, clientSecret, accessKey, secretKey, tenantedDeploymentMode),
Config: testAccountBasic(localName, name, accountType, applicationID, tenantID, subscriptionID, clientSecret, accessKey, secretKey, tenantedDeploymentMode),
},
},
})
}

func testAccountBasic(localName string, name string, accountType octopusdeploy.AccountType, clientID uuid.UUID, tenantID uuid.UUID, subscriptionID uuid.UUID, clientSecret string, accessKey string, secretKey string, tenantedDeploymentParticipation octopusdeploy.TenantedDeploymentMode) string {
func testAccountBasic(localName string, name string, accountType octopusdeploy.AccountType, applicationID uuid.UUID, tenantID uuid.UUID, subscriptionID uuid.UUID, clientSecret string, accessKey string, secretKey string, tenantedDeploymentParticipation octopusdeploy.TenantedDeploymentMode) string {
return fmt.Sprintf(`resource "octopusdeploy_account" "%s" {
account_type = "%s"
client_id = "%s"
application_id = "%s"
client_secret = "%s"
name = "%s"
subscription_id = "%s"
tenant_id = "%s"
tenanted_deployment_participation = "%s"
}`, localName, accountType, clientID, clientSecret, name, subscriptionID, tenantID, tenantedDeploymentParticipation)
}`, localName, accountType, applicationID, clientSecret, name, subscriptionID, tenantID, tenantedDeploymentParticipation)
}

func testAccAccountExists(prefix string) resource.TestCheckFunc {
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/resource_aws_account.go
Expand Up @@ -23,7 +23,7 @@ func resourceAmazonWebServicesAccount() *schema.Resource {

func resourceAmazonWebServicesAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
account := expandAmazonWebServicesAccount(d)

log.Printf("[INFO] creating AWS account: %#v", account)

client := m.(*octopusdeploy.Client)
Expand Down
55 changes: 31 additions & 24 deletions octopusdeploy/resource_deployment_process.go
Expand Up @@ -24,23 +24,25 @@ func resourceDeploymentProcess() *schema.Resource {
func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
deploymentProcess := expandDeploymentProcess(d)

log.Printf("[INFO] creating deployment process: %#v", deploymentProcess)

client := m.(*octopusdeploy.Client)
project, err := client.Projects.GetByID(deploymentProcess.ProjectID)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

current, err := client.DeploymentProcesses.GetByID(project.DeploymentProcessID)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

deploymentProcess.ID = current.ID
deploymentProcess.Version = current.Version

resource, err := client.DeploymentProcesses.Update(deploymentProcess)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

if isEmpty(resource.GetID()) {
Expand All @@ -49,6 +51,32 @@ func resourceDeploymentProcessCreate(ctx context.Context, d *schema.ResourceData
d.SetId(resource.GetID())
}

log.Printf("[INFO] deployment process created (%s)", d.Id())
return nil
}

func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Printf("[INFO] deleting deployment process (%s)", d.Id())

client := m.(*octopusdeploy.Client)
current, err := client.DeploymentProcesses.GetByID(d.Id())
if err != nil {
return diag.FromErr(err)
}

deploymentProcess := &octopusdeploy.DeploymentProcess{
Version: current.Version,
}
deploymentProcess.ID = d.Id()

_, err = client.DeploymentProcesses.Update(deploymentProcess)
if err != nil {
return diag.FromErr(err)
}

d.SetId("")

log.Printf("[INFO] deployment process deleted")
return nil
}

Expand Down Expand Up @@ -87,24 +115,3 @@ func resourceDeploymentProcessUpdate(ctx context.Context, d *schema.ResourceData

return nil
}

func resourceDeploymentProcessDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*octopusdeploy.Client)
current, err := client.DeploymentProcesses.GetByID(d.Id())
if err != nil {
return diag.FromErr(err)
}

deploymentProcess := &octopusdeploy.DeploymentProcess{
Version: current.Version,
}
deploymentProcess.ID = d.Id()

_, err = client.DeploymentProcesses.Update(deploymentProcess)
if err != nil {
return diag.FromErr(err)
}

d.SetId("")
return nil
}
2 changes: 1 addition & 1 deletion octopusdeploy/resource_sshkey_account.go
Expand Up @@ -29,7 +29,7 @@ func resourceSSHKeyAccountCreate(ctx context.Context, d *schema.ResourceData, m
client := m.(*octopusdeploy.Client)
createdAccount, err := client.Accounts.Add(account)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

if err := setSSHKeyAccount(ctx, d, createdAccount.(*octopusdeploy.SSHKeyAccount)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions octopusdeploy/resource_username_password_account.go
Expand Up @@ -29,7 +29,7 @@ func resourceUsernamePasswordAccountCreate(ctx context.Context, d *schema.Resour
client := m.(*octopusdeploy.Client)
createdAccount, err := client.Accounts.Add(account)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

if err := setUsernamePasswordAccount(ctx, d, createdAccount.(*octopusdeploy.UsernamePasswordAccount)); err != nil {
Expand Down Expand Up @@ -94,7 +94,7 @@ func resourceUsernamePasswordAccountUpdate(ctx context.Context, d *schema.Resour
client := m.(*octopusdeploy.Client)
accountResource, err := client.Accounts.Update(account)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

accountResource, err = octopusdeploy.ToAccount(accountResource.(*octopusdeploy.AccountResource))
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_deployment_step.go
Expand Up @@ -24,7 +24,7 @@ func expandDeploymentStep(tfStep map[string]interface{}) octopusdeploy.Deploymen

conditionExpression := tfStep["condition_expression"]
if conditionExpression != nil {
step.Properties["Octopus.Action.ConditionVariableExpression"] = conditionExpression.(string)
step.Properties["Octopus.Step.ConditionVariableExpression"] = conditionExpression.(string)
}

windowSize := tfStep["window_size"]
Expand Down

0 comments on commit 354c33f

Please sign in to comment.