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.
pull/34838/head
Martin Atkins 2 years ago
parent 5d87e32eb9
commit 621befc3a2

@ -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("<TestWrapConfig>", obj.AsValueMap())
return configtesting.SynthBody("<TestWrapConfig>", obj.AsValueMap())
}
// TestBackend will test the functionality of a Backend. The backend is

@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package configs
package configtesting
import (
"fmt"

@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package configs
package configtesting
import (
"testing"

@ -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)
}

Loading…
Cancel
Save