Skip to content

Commit

Permalink
add test to verify immutable resource data
Browse files Browse the repository at this point in the history
  • Loading branch information
austinvalle committed Nov 15, 2024
1 parent 7f8b981 commit 10123e5
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions echoprovider/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,51 @@ func TestEchoProviderServer_unknown(t *testing.T) {
},
})
}

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

resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_0_0), // echo provider is protocol version 6
},
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"echo": echoprovider.NewProviderServer(),
},
Steps: []resource.TestStep{
{
Config: `
provider "echo" {
data = "original value"
}
resource "echo" "test_one" {}
`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectUnknownValue("echo.test_one", tfjsonpath.New("data")),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("echo.test_one", tfjsonpath.New("data"), knownvalue.StringExact("original value")),
},
},
{
// Despite the provider config data changing the "echo.test_one" resource will never change as it's immutable.
Config: `
provider "echo" {
data = ["tuple", "of", "values"]
}
resource "echo" "test_one" {}
`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("echo.test_one", tfjsonpath.New("data"), knownvalue.StringExact("original value")),
},
},
},
})
}

0 comments on commit 10123e5

Please sign in to comment.