Skip to content

Commit

Permalink
Add new tests, configurations and fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroden84 committed Aug 9, 2024
1 parent 65e7f03 commit 89bda83
Show file tree
Hide file tree
Showing 7 changed files with 6,132 additions and 0 deletions.
193 changes: 193 additions & 0 deletions cloudamqp/resource_cloudamqp_upgrade_rabbitmq_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package cloudamqp

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/vcr-testing/configuration"
"github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/vcr-testing/converter"
)

// TestAccUpgradeRabbitMQ_Latest: Upgrade RabbitMQ to latest possible version, from 3.12.2 -> 3.13.2
// Extra checks are needed when comparing versions, because next step is executed before backend
// have been updated. Same reason unable to use cloudamqp_upgradable_versions data source correctly.
func TestAccUpgradeRabbitMQ_Latest(t *testing.T) {
var (
fileNames = []string{"instance_with_version", "data_source/nodes"}
instanceResourceName = "cloudamqp_instance.instance"
dataSourceNodesName = "data.cloudamqp_nodes.nodes"

params = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"InstanceRmqVersion": "3.12.2",
}

fileNamesUpgrade = []string{"instance", "data_source/nodes", "upgrade_rabbitmq_latest"}

paramsUpgrade01 = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeRabbitMQCurrentVersion": "3.12.2",
"UpgradeRabbitMQNewVersion": "3.12.13",
}

paramsUpgrade02 = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeRabbitMQCurrentVersion": "3.12.13",
"UpgradeRabbitMQNewVersion": "3.13.2",
}

fileNamesCheckUpgrade = []string{"instance", "data_source/nodes"}
paramsCheck = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
}
)

cloudamqpResourceTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactory,
Steps: []resource.TestStep{
{
Config: configuration.GetTemplatedConfig(t, fileNames, params),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]),
resource.TestCheckResourceAttr(instanceResourceName, "plan", "bunny-1"),
resource.TestCheckResourceAttr(instanceResourceName, "region", "amazon-web-services::us-east-1"),
resource.TestCheckResourceAttr(instanceResourceName, "rmq_version", params["InstanceRmqVersion"]),
resource.TestCheckResourceAttr(instanceResourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(instanceResourceName, "tags.0", "terraform"),
resource.TestCheckResourceAttr(instanceResourceName, "nodes", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", params["InstanceRmqVersion"]),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesUpgrade, paramsUpgrade01),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.2"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.13"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesUpgrade, paramsUpgrade02),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.13"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.13.2"),
),
},
},
})
}

// TestAccUpgradeRabbitMQ_Specific: Upgrade RabbitMQ to a specific version, from 3.12.2 -> 3.13.2
// Extra checks are needed when comparing versions, because next step is executed before backend
// have been updated.
func TestAccUpgradeRabbitMQ_Specific(t *testing.T) {
var (
fileNames = []string{"instance_with_version", "data_source/nodes"}
instanceResourceName = "cloudamqp_instance.instance"
dataSourceNodesName = "data.cloudamqp_nodes.nodes"

params = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"InstanceRmqVersion": "3.12.2",
}

fileNamesUpgrade = []string{"instance", "data_source/nodes", "upgrade_rabbitmq_latest"}

paramsUpgrade01 = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeRabbitMQNewVersion": "3.12.13",
}

paramsUpgrade02 = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeRabbitMQNewVersion": "3.13.2",
}

fileNamesCheckUpgrade = []string{"instance", "data_source/nodes"}
paramsCheck = map[string]string{
"InstanceName": "TestAccUpgradeRabbitMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
}
)

cloudamqpResourceTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactory,
Steps: []resource.TestStep{
{
Config: configuration.GetTemplatedConfig(t, fileNames, params),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]),
resource.TestCheckResourceAttr(instanceResourceName, "plan", "bunny-1"),
resource.TestCheckResourceAttr(instanceResourceName, "region", "amazon-web-services::us-east-1"),
resource.TestCheckResourceAttr(instanceResourceName, "rmq_version", params["InstanceRmqVersion"]),
resource.TestCheckResourceAttr(instanceResourceName, "tags.#", "1"),
resource.TestCheckResourceAttr(instanceResourceName, "tags.0", "terraform"),
resource.TestCheckResourceAttr(instanceResourceName, "nodes", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", params["InstanceRmqVersion"]),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesUpgrade, paramsUpgrade01),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.2"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.13"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesUpgrade, paramsUpgrade02),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.12.13"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "3.13.2"),
),
},
},
})
}
3 changes: 3 additions & 0 deletions test/configurations/data_source/upgradable_versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "cloudamqp_upgradable_versions" "upgrade" {
instance_id = {{.InstanceID}}
}
7 changes: 7 additions & 0 deletions test/configurations/instance_with_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "cloudamqp_instance" "instance" {
name = "{{or .InstanceName `TestAccInstance`}}"
plan = "{{or .InstancePlan `bunny-1`}}"
region = "{{or .InstanceRegion `amazon-web-services::us-east-1`}}"
tags = {{or .InstanceTags `["terraform"]`}}
rmq_version = "{{.InstanceRmqVersion}}"
}
5 changes: 5 additions & 0 deletions test/configurations/upgrade_rabbitmq_latest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "cloudamqp_upgrade_rabbitmq" "upgrade" {
instance_id = {{.InstanceID}}
current_version = "{{.UpgradeRabbitMQCurrentVersion}}"
new_version = "{{.UpgradeRabbitMQNewVersion}}"
}
4 changes: 4 additions & 0 deletions test/configurations/upgrade_rabbitmq_specific.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "cloudamqp_upgrade_rabbitmq" "upgrade" {
instance_id = {{.InstanceID}}
new_version = "{{.UpgradeRabbitMQNewVersion}}"
}
3,470 changes: 3,470 additions & 0 deletions test/fixtures/vcr/TestAccUpgradeRabbitMQ_Latest.yaml

Large diffs are not rendered by default.

2,450 changes: 2,450 additions & 0 deletions test/fixtures/vcr/TestAccUpgradeRabbitMQ_Specific.yaml

Large diffs are not rendered by default.

0 comments on commit 89bda83

Please sign in to comment.