Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
tinkerbell: prepare for testing multiple resources in parallel
Browse files Browse the repository at this point in the history
This commit makes sure that testing configuration generates unique
resource names, so multiple outputs can be combined and executed by
Terraform in parallel.

As a preparation to test mitigations against
tinkerbell/tink#338.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Oct 12, 2020
1 parent 8435a81 commit 28bd5d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
26 changes: 13 additions & 13 deletions tinkerbell/resource_hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func testAccHardwareConfig(uuid string, mac string) string {
`, uuid, mac)
}

func testAccHardware(data string) string {
func testAccHardware(data, name string) string {
return fmt.Sprintf(`
resource "tinkerbell_hardware" "foo" {
resource "tinkerbell_hardware" "%s" {
data = <<EOF
%s
EOF
}
`, data)
`, name, data)
}

func newUUID(t *testing.T) string {
Expand All @@ -86,7 +86,7 @@ func TestAccHardware_create(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC), "foo"),
},
},
})
Expand All @@ -102,10 +102,10 @@ func TestAccHardware_detectChanges(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC), "foo"),
},
{
Config: testAccHardware(testAccHardwareConfig(rUUID, nMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, nMAC), "foo"),
ExpectNonEmptyPlan: true,
PlanOnly: true,
},
Expand All @@ -123,10 +123,10 @@ func TestAccHardware_update(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC), "foo"),
},
{
Config: testAccHardware(testAccHardwareConfig(rUUID, nMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, nMAC), "foo"),
},
},
})
Expand All @@ -142,10 +142,10 @@ func TestAccHardware_updateUUID(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC), "foo"),
},
{
Config: testAccHardware(testAccHardwareConfig(nUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(nUUID, rMAC), "foo"),
},
},
})
Expand All @@ -160,10 +160,10 @@ func TestAccHardware_ignoreWhitespace(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC)),
Config: testAccHardware(testAccHardwareConfig(rUUID, rMAC), "foo"),
},
{
Config: testAccHardware(fmt.Sprintf("%s\n", testAccHardwareConfig(rUUID, rMAC))),
Config: testAccHardware(fmt.Sprintf("%s\n", testAccHardwareConfig(rUUID, rMAC)), "foo"),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
Expand All @@ -177,7 +177,7 @@ func TestAccHardware_validateData(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHardware("bad json"),
Config: testAccHardware("bad json", "foo"),
ExpectError: regexp.MustCompile(`failed decoding 'data' as JSON`),
},
},
Expand Down
4 changes: 2 additions & 2 deletions tinkerbell/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

func testAccTemplate(name, content string) string {
return fmt.Sprintf(`
resource "tinkerbell_template" "foo" {
resource "tinkerbell_template" "a%s" {
name = "%s"
content = <<EOF
%s
EOF
}
`, name, content)
`, name, name, content)
}

func testAccTemplateContent(timeout int) string {
Expand Down
16 changes: 10 additions & 6 deletions tinkerbell/resource_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func testAccWorkflow(t *testing.T) string {
func testAccWorkflow(t *testing.T, id int) string {
name := newUUID(t)
rMAC := newMAC(t)
resourceName := fmt.Sprintf("foo%d", id)

return fmt.Sprintf(`
%s
%s
resource "tinkerbell_workflow" "foo" {
template = tinkerbell_template.foo.id
resource "tinkerbell_workflow" "%s" {
template = tinkerbell_template.a%s.id
hardwares = <<EOF
{"device_1":"%s"}
EOF
depends_on = [
tinkerbell_hardware.foo,
tinkerbell_hardware.%s,
]
}
`,
testAccHardware(testAccHardwareConfig(name, rMAC)),
testAccHardware(testAccHardwareConfig(name, rMAC), resourceName),
testAccTemplate(name, testAccTemplateContent(1)),
resourceName,
name,
rMAC,
resourceName,
)
}

Expand All @@ -39,7 +43,7 @@ func TestAccWorkflow_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccWorkflow(t),
Config: testAccWorkflow(t, 0),
},
},
})
Expand Down

0 comments on commit 28bd5d0

Please sign in to comment.