Skip to content

Commit

Permalink
add test and fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorerlingsson committed Sep 2, 2024
1 parent 85c6a16 commit 139e110
Show file tree
Hide file tree
Showing 5 changed files with 2,174 additions and 0 deletions.
163 changes: 163 additions & 0 deletions cloudamqp/resource_cloudamqp_upgrade_lavinmq_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
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"
)

// TestAccUpgradeLavinMQ_Latest: Upgrade LavinMQ to latest possible version, from 1.3.0 -> 2.0.0-rc.3
// 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 TestAccUpgradeLavinMQ_Latest(t *testing.T) {
var (
fileNames = []string{"instance_with_version_lavinmq", "data_source/nodes"}
instanceResourceName = "cloudamqp_instance.instance"
dataSourceNodesName = "data.cloudamqp_nodes.nodes"

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

fileNamesUpgrade = []string{"instance_lavinmq", "data_source/nodes", "upgrade_lavinmq_latest"}

paramsUpgrade01 = map[string]string{
"InstanceName": "TestAccUpgradeLavinMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeLavinMQNewVersion": "2.0.0-rc.3",
}

fileNamesCheckUpgrade = []string{"instance_lavinmq", "data_source/nodes"}
paramsCheck = map[string]string{
"InstanceName": "TestAccUpgradeLavinMQ_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", "wolverine-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", "1.3.0"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"),
),
},
},
})
}

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

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

fileNamesUpgrade = []string{"instance_lavinmq", "data_source/nodes", "upgrade_lavinmq_latest"}

paramsUpgrade01 = map[string]string{
"InstanceName": "TestAccUpgradeLavinMQ_Latest",
"InstanceTags": converter.CommaStringArray([]string{"terraform"}),
"InstanceID": fmt.Sprintf("%s.id", instanceResourceName),
"UpgradeLavinMQNewVersion": "2.0.0-rc.3",
}

fileNamesCheckUpgrade = []string{"instance_lavinmq", "data_source/nodes"}
paramsCheck = map[string]string{
"InstanceName": "TestAccUpgradeLavinMQ_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", "wolverine-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", "1.3.0"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"),
),
},
{
Config: configuration.GetTemplatedConfig(t, fileNamesCheckUpgrade, paramsCheck),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.#", "1"),
resource.TestCheckResourceAttr(dataSourceNodesName, "nodes.0.rabbitmq_version", "2.0.0-rc.3"),
),
},
},
})
}
6 changes: 6 additions & 0 deletions test/configurations/instance_lavinmq.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "cloudamqp_instance" "instance" {
name = "{{or .InstanceName `TestAccInstance`}}"
plan = "{{or .InstancePlan `wolverine-1`}}"
region = "{{or .InstanceRegion `amazon-web-services::us-east-1`}}"
tags = {{or .InstanceTags `["terraform"]`}}
}
7 changes: 7 additions & 0 deletions test/configurations/instance_with_version_lavinmq.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 `wolverine-1`}}"
region = "{{or .InstanceRegion `amazon-web-services::us-east-1`}}"
tags = {{or .InstanceTags `["terraform"]`}}
rmq_version = "{{.InstanceRmqVersion}}"
}
4 changes: 4 additions & 0 deletions test/configurations/upgrade_lavinmq_latest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "cloudamqp_upgrade_lavinmq" "upgrade" {
instance_id = {{.InstanceID}}
new_version = "{{.UpgradeLavinMQNewVersion}}"
}
Loading

0 comments on commit 139e110

Please sign in to comment.