Skip to content

Commit

Permalink
Adding test to demonstrate that the TestStep number is being used dyn…
Browse files Browse the repository at this point in the history
…amically to determine the directory containing the Terraform configuration (#150)
  • Loading branch information
bendbennett committed Jul 31, 2023
1 parent 51576a0 commit a95efe7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
}

provider "random" {}

resource "random_password" "test" {
length = 8

numeric = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

terraform {
required_providers {
random = {
source = "registry.terraform.io/hashicorp/random"
version = "3.5.1"
}
}
}

provider "random" {}

resource "random_password" "test" {
length = 9

numeric = false
}
20 changes: 20 additions & 0 deletions helper/resource/teststep_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
"github.com/hashicorp/terraform-plugin-testing/internal/teststep"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

Expand Down Expand Up @@ -2333,6 +2334,25 @@ func TestTest_ConfigDirectory_TestStepDirectory(t *testing.T) {
})
}

// TestTest_ConfigDirectory_TestStepDirectory_StepNotHardcoded uses a multistep test
// to prove that the test step number is not hardcoded
func TestTest_ConfigDirectory_TestStepDirectory_StepNotHardcoded(t *testing.T) {
t.Parallel()

Test(t, TestCase{
Steps: []TestStep{
{
ConfigDirectory: config.TestStepDirectory(),
Check: TestCheckResourceAttrPtr("random_password.test", "length", teststep.Pointer("8")),
},
{
ConfigDirectory: config.TestStepDirectory(),
Check: TestCheckResourceAttrPtr("random_password.test", "length", teststep.Pointer("9")),
},
},
})
}

func TestTest_ConfigDirectory_TestStepDirectory_Vars(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a95efe7

Please sign in to comment.