From 621befc3a24a51a99da6cf5f604634bf24a37804 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 13 Mar 2024 15:54:54 -0700 Subject: [PATCH] configtesting: Separate package for the SynthBody helper This "SynthBody" helper doesn't really have anything to do with package configs except that it's sometimes useful for creating fake instances of the types in there for testing. Moving it into its own package means that package backend no longer needs to depend on package configs, since it doesn't actually have any need for parsing module configurations. The old configs.SynthBody function is still available as a forwarding alias, because most of the existing callers of it are from packages that already need to import package configs for other reasons, and so this reduces the need to churn loads of existing tests. --- internal/backend/testing.go | 4 ++-- internal/configs/{ => configtesting}/synth_body.go | 2 +- .../configs/{ => configtesting}/synth_body_test.go | 2 +- internal/configs/util.go | 13 +++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) rename internal/configs/{ => configtesting}/synth_body.go (99%) rename internal/configs/{ => configtesting}/synth_body_test.go (98%) diff --git a/internal/backend/testing.go b/internal/backend/testing.go index af9f355114..843adad64a 100644 --- a/internal/backend/testing.go +++ b/internal/backend/testing.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/terraform/internal/addrs" - "github.com/hashicorp/terraform/internal/configs" + "github.com/hashicorp/terraform/internal/configs/configtesting" "github.com/hashicorp/terraform/internal/configs/hcl2shim" "github.com/hashicorp/terraform/internal/states" "github.com/hashicorp/terraform/internal/states/statemgr" @@ -68,7 +68,7 @@ func TestBackendConfig(t *testing.T, b Backend, c hcl.Body) Backend { // this function will panic. func TestWrapConfig(raw map[string]interface{}) hcl.Body { obj := hcl2shim.HCL2ValueFromConfigValue(raw) - return configs.SynthBody("", obj.AsValueMap()) + return configtesting.SynthBody("", obj.AsValueMap()) } // TestBackend will test the functionality of a Backend. The backend is diff --git a/internal/configs/synth_body.go b/internal/configs/configtesting/synth_body.go similarity index 99% rename from internal/configs/synth_body.go rename to internal/configs/configtesting/synth_body.go index 479251b2df..39e61a1553 100644 --- a/internal/configs/synth_body.go +++ b/internal/configs/configtesting/synth_body.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package configs +package configtesting import ( "fmt" diff --git a/internal/configs/synth_body_test.go b/internal/configs/configtesting/synth_body_test.go similarity index 98% rename from internal/configs/synth_body_test.go rename to internal/configs/configtesting/synth_body_test.go index cbf842d2fd..5c708bb42d 100644 --- a/internal/configs/synth_body_test.go +++ b/internal/configs/configtesting/synth_body_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package configs +package configtesting import ( "testing" diff --git a/internal/configs/util.go b/internal/configs/util.go index 019f57598e..5315ac1a0f 100644 --- a/internal/configs/util.go +++ b/internal/configs/util.go @@ -6,6 +6,9 @@ package configs import ( "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/hclsyntax" + "github.com/zclconf/go-cty/cty" + + "github.com/hashicorp/terraform/internal/configs/configtesting" ) // exprIsNativeQuotedString determines whether the given expression looks like @@ -64,3 +67,13 @@ func schemaWithDynamic(schema *hcl.BodySchema) *hcl.BodySchema { return ret } + +// SynthBody is a forwarding alias for the old location of +// [configtesting.SynthBody]. +// +// Using the new name is preferable because it might avoid you needing to +// import this entire configs package, if you didn't have some other +// use for it anyway. +func SynthBody(filename string, values map[string]cty.Value) hcl.Body { + return configtesting.SynthBody(filename, values) +}