mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 19:22:46 -06:00
5d5a670d69
Added a list SetNew test to try and reproduce issues testing diff customization with the Nomad provider. We are running into "diffs didn't match during apply", with the plan diff exhibiting a strange off-by-one-type error in a list diff: datacenters.#: "1" => "2" datacenters.0: "dc1" => "dc2" datacenters.1: "" => "dc3" datacenters.2: "" => "dc3" The test here does not reproduce that issue, unfortunately, but should help pinpoint the root cause through elimination.
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
// TestResourceWithCustomDiff test custom diff behaviour.
|
|
func TestResourceWithCustomDiff(t *testing.T) {
|
|
resource.UnitTest(t, resource.TestCase{
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: resourceWithCustomDiffConfig(false),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "computed", "1"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "index", "1"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.#", "1"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.0", "dc1"),
|
|
),
|
|
ExpectNonEmptyPlan: true,
|
|
},
|
|
{
|
|
Config: resourceWithCustomDiffConfig(false),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "computed", "2"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "index", "2"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.#", "2"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.0", "dc2"),
|
|
resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.1", "dc3"),
|
|
resource.TestCheckNoResourceAttr("test_resource_with_custom_diff.foo", "list.2"),
|
|
),
|
|
ExpectNonEmptyPlan: true,
|
|
},
|
|
{
|
|
Config: resourceWithCustomDiffConfig(true),
|
|
ExpectError: regexp.MustCompile("veto is true, diff vetoed"),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func resourceWithCustomDiffConfig(veto bool) string {
|
|
return fmt.Sprintf(`
|
|
resource "test_resource_with_custom_diff" "foo" {
|
|
required = "yep"
|
|
veto = %t
|
|
}
|
|
`, veto)
|
|
}
|