From 392ed7c42581c91b3da5c43ea22301097990072f Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Wed, 17 Apr 2024 13:52:54 -0400 Subject: [PATCH] website: Update testing documentation to utilize new `statecheck` and `knownvalue` packages (#982) --- .../plugin/framework/functions/testing.mdx | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/website/docs/plugin/framework/functions/testing.mdx b/website/docs/plugin/framework/functions/testing.mdx index a21f1ad7f..43d9b72b9 100644 --- a/website/docs/plugin/framework/functions/testing.mdx +++ b/website/docs/plugin/framework/functions/testing.mdx @@ -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" ) @@ -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")), + }, }, }, }) @@ -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`), }, }, @@ -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`), }, }, @@ -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")), + }, }, }, })