Skip to content

Commit

Permalink
website: Update testing documentation to utilize new statecheck and…
Browse files Browse the repository at this point in the history
… `knownvalue` packages
  • Loading branch information
austinvalle committed Apr 17, 2024
1 parent de32b2c commit 914fb8c
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions website/docs/plugin/framework/functions/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

Expand All @@ -59,11 +61,12 @@ func TestEchoFunction_Valid(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::example::echo("test-value")
}
`,
Check: resource.TestCheckOutput("test", "test-value"),
output "test" {
value = provider::example::echo("test-value")
}`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownOutputValue("test", knownvalue.StringExact("test-value")),
},
},
},
})
Expand All @@ -84,10 +87,9 @@ func TestEchoFunction_Invalid(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::example::echo("invalid")
}
`,
output "test" {
value = provider::example::echo("invalid")
}`,
ExpectError: regexp.MustCompile(`error summary`),
},
},
Expand All @@ -109,10 +111,9 @@ func TestEchoFunction_Null(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::example::echo(null)
}
`,
output "test" {
value = provider::example::echo(null)
}`,
ExpectError: regexp.MustCompile(`Invalid Function Call`),
},
},
Expand All @@ -132,20 +133,21 @@ func TestEchoFunction_Unknown(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
terraform_data "test" {
input = "test-value"
}
output "test" {
value = provider::example::echo(terraform_data.test.output)
}
`,
Check: resource.TestCheckOutput("test", "test-value"),
terraform_data "test" {
input = "test-value"
}
output "test" {
value = provider::example::echo(terraform_data.test.output)
}`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectUnknownOutputValue("test"),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownOutputValue("test", knownvalue.StringExact("test-value")),
},
},
},
})
Expand Down

0 comments on commit 914fb8c

Please sign in to comment.