2023-05-02 10:33:06 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-11-14 00:04:21 -06:00
|
|
|
package repl
|
|
|
|
|
|
|
|
import (
|
2018-10-02 19:02:48 -05:00
|
|
|
"flag"
|
|
|
|
"os"
|
2016-11-14 00:04:21 -06:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-02-09 16:17:14 -06:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2018-10-02 19:21:50 -05:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
2023-08-17 07:45:11 -05:00
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/addrs"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/configs/configschema"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/initwd"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/providers"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/states"
|
|
|
|
"github.com/placeholderplaceholderplaceholder/opentf/internal/terraform"
|
2020-10-18 09:01:48 -05:00
|
|
|
|
2023-08-17 07:45:11 -05:00
|
|
|
_ "github.com/placeholderplaceholderplaceholder/opentf/internal/logging"
|
2016-11-14 00:04:21 -06:00
|
|
|
)
|
|
|
|
|
2018-10-02 19:02:48 -05:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
flag.Parse()
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
2016-11-14 00:04:21 -06:00
|
|
|
func TestSession_basicState(t *testing.T) {
|
2018-10-02 19:02:48 -05:00
|
|
|
state := states.BuildState(func(s *states.SyncState) {
|
2018-09-28 19:15:35 -05:00
|
|
|
s.SetResourceInstanceCurrent(
|
|
|
|
addrs.Resource{
|
|
|
|
Mode: addrs.ManagedResourceMode,
|
|
|
|
Type: "test_instance",
|
|
|
|
Name: "foo",
|
|
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
2018-10-02 19:02:48 -05:00
|
|
|
Status: states.ObjectReady,
|
2018-09-28 19:15:35 -05:00
|
|
|
AttrsJSON: []byte(`{"id":"bar"}`),
|
2016-11-14 00:04:21 -06:00
|
|
|
},
|
2020-02-13 14:32:58 -06:00
|
|
|
addrs.AbsProviderConfig{
|
2020-04-03 13:20:24 -05:00
|
|
|
Provider: addrs.NewDefaultProvider("test"),
|
2020-03-11 13:19:52 -05:00
|
|
|
Module: addrs.RootModule,
|
2020-02-13 14:32:58 -06:00
|
|
|
},
|
2018-09-28 19:15:35 -05:00
|
|
|
)
|
|
|
|
s.SetResourceInstanceCurrent(
|
|
|
|
addrs.Resource{
|
|
|
|
Mode: addrs.ManagedResourceMode,
|
|
|
|
Type: "test_instance",
|
|
|
|
Name: "foo",
|
|
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance.Child("module", addrs.NoKey)),
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
2018-10-02 19:02:48 -05:00
|
|
|
Status: states.ObjectReady,
|
2018-09-28 19:15:35 -05:00
|
|
|
AttrsJSON: []byte(`{"id":"bar"}`),
|
2016-11-14 00:17:51 -06:00
|
|
|
},
|
2020-02-13 14:32:58 -06:00
|
|
|
addrs.AbsProviderConfig{
|
2020-04-03 13:20:24 -05:00
|
|
|
Provider: addrs.NewDefaultProvider("test"),
|
2020-03-11 13:19:52 -05:00
|
|
|
Module: addrs.RootModule,
|
2020-02-13 14:32:58 -06:00
|
|
|
},
|
2018-09-28 19:15:35 -05:00
|
|
|
)
|
|
|
|
})
|
2016-11-14 00:04:21 -06:00
|
|
|
|
|
|
|
t.Run("basic", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "test_instance.foo.id",
|
2020-09-09 13:13:53 -05:00
|
|
|
Output: `"bar"`,
|
2016-11-14 00:04:21 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("missing resource", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "test_instance.bar.id",
|
|
|
|
Error: true,
|
2018-11-20 19:25:05 -06:00
|
|
|
ErrorContains: `A managed resource "test_instance" "bar" has not been declared`,
|
2016-11-14 00:04:21 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2016-11-14 00:17:51 -06:00
|
|
|
|
|
|
|
t.Run("missing module", func(t *testing.T) {
|
2018-11-28 13:25:44 -06:00
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "module.child",
|
|
|
|
Error: true,
|
|
|
|
ErrorContains: `No module call named "child" is declared in the root module.`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("missing module referencing just one output", func(t *testing.T) {
|
2016-11-14 00:17:51 -06:00
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "module.child.foo",
|
|
|
|
Error: true,
|
2018-11-28 13:25:44 -06:00
|
|
|
ErrorContains: `No module call named "child" is declared in the root module.`,
|
2016-11-14 00:17:51 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("missing module output", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "module.module.foo",
|
|
|
|
Error: true,
|
2020-04-14 13:50:43 -05:00
|
|
|
ErrorContains: `Unsupported attribute: This object does not have an attribute named "foo"`,
|
2016-11-14 00:17:51 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2022-02-04 09:32:06 -06:00
|
|
|
|
|
|
|
t.Run("type function", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
State: state,
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "type(test_instance.foo)",
|
|
|
|
Output: `object({
|
|
|
|
id: string,
|
|
|
|
})`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSession_stateless(t *testing.T) {
|
|
|
|
t.Run("exit", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
2018-09-28 19:15:35 -05:00
|
|
|
Input: "exit",
|
|
|
|
Exit: true,
|
2016-11-14 00:04:21 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("help", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "help",
|
|
|
|
OutputContains: "allows you to",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("help with spaces", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "help ",
|
|
|
|
OutputContains: "allows you to",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("basic math", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "1 + 5",
|
|
|
|
Output: "6",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("missing resource", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: "test_instance.bar.id",
|
|
|
|
Error: true,
|
2018-09-28 19:15:35 -05:00
|
|
|
ErrorContains: `resource "test_instance" "bar" has not been declared`,
|
2016-11-14 00:04:21 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2022-02-04 09:32:06 -06:00
|
|
|
|
2022-02-09 16:17:14 -06:00
|
|
|
t.Run("type function", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: `type("foo")`,
|
|
|
|
Output: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("type type is type", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: `type(type("foo"))`,
|
|
|
|
Output: "type",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("interpolating type with strings is not possible", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: `"quin${type([])}"`,
|
|
|
|
Error: true,
|
|
|
|
ErrorContains: "Invalid template interpolation value",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-02-04 09:32:06 -06:00
|
|
|
t.Run("type function cannot be used in expressions", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: `[for i in [1, "two", true]: type(i)]`,
|
2022-02-09 16:17:14 -06:00
|
|
|
Output: "",
|
|
|
|
Error: true,
|
|
|
|
ErrorContains: "Invalid use of type function",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("type equality checks are not permitted", func(t *testing.T) {
|
|
|
|
testSession(t, testSessionTest{
|
|
|
|
Inputs: []testSessionInput{
|
|
|
|
{
|
|
|
|
Input: `type("foo") == type("bar")`,
|
|
|
|
Output: "",
|
2022-02-04 09:32:06 -06:00
|
|
|
Error: true,
|
|
|
|
ErrorContains: "Invalid use of type function",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func testSession(t *testing.T, test testSessionTest) {
|
2018-11-20 19:25:05 -06:00
|
|
|
t.Helper()
|
|
|
|
|
2018-09-28 19:15:35 -05:00
|
|
|
p := &terraform.MockProvider{}
|
2021-02-18 09:13:43 -06:00
|
|
|
p.GetProviderSchemaResponse = &providers.GetProviderSchemaResponse{
|
2021-01-12 15:13:10 -06:00
|
|
|
ResourceTypes: map[string]providers.Schema{
|
2018-10-02 19:21:50 -05:00
|
|
|
"test_instance": {
|
2021-01-12 15:13:10 -06:00
|
|
|
Block: &configschema.Block{
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"id": {Type: cty.String, Computed: true},
|
|
|
|
},
|
2018-10-02 19:21:50 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-07-19 03:07:46 -05:00
|
|
|
config, _, cleanup, configDiags := initwd.LoadConfigForTests(t, "testdata/config-fixture", "tests")
|
2018-10-02 19:21:50 -05:00
|
|
|
defer cleanup()
|
|
|
|
if configDiags.HasErrors() {
|
2019-01-08 20:39:14 -06:00
|
|
|
t.Fatalf("unexpected problems loading config: %s", configDiags.Err())
|
2018-10-02 19:21:50 -05:00
|
|
|
}
|
2018-09-28 19:15:35 -05:00
|
|
|
|
2016-11-14 00:04:21 -06:00
|
|
|
// Build the TF context
|
2018-09-28 19:15:35 -05:00
|
|
|
ctx, diags := terraform.NewContext(&terraform.ContextOpts{
|
2020-04-03 13:20:24 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("test"): providers.FactoryFixed(p),
|
|
|
|
},
|
2016-11-14 00:04:21 -06:00
|
|
|
})
|
2018-09-28 19:15:35 -05:00
|
|
|
if diags.HasErrors() {
|
|
|
|
t.Fatalf("failed to create context: %s", diags.Err())
|
|
|
|
}
|
|
|
|
|
core: Functional-style API for terraform.Context
Previously terraform.Context was built in an unfortunate way where all of
the data was provided up front in terraform.NewContext and then mutated
directly by subsequent operations. That made the data flow hard to follow,
commonly leading to bugs, and also meant that we were forced to take
various actions too early in terraform.NewContext, rather than waiting
until a more appropriate time during an operation.
This (enormous) commit changes terraform.Context so that its fields are
broadly just unchanging data about the execution context (current
workspace name, available plugins, etc) whereas the main data Terraform
works with arrives via individual method arguments and is returned in
return values.
Specifically, this means that terraform.Context no longer "has-a" config,
state, and "planned changes", instead holding on to those only temporarily
during an operation. The caller is responsible for propagating the outcome
of one step into the next step so that the data flow between operations is
actually visible.
However, since that's a change to the main entry points in the "terraform"
package, this commit also touches every file in the codebase which
interacted with those APIs. Most of the noise here is in updating tests
to take the same actions using the new API style, but this also affects
the main-code callers in the backends and in the command package.
My goal here was to refactor without changing observable behavior, but in
practice there are a couple externally-visible behavior variations here
that seemed okay in service of the broader goal:
- The "terraform graph" command is no longer hooked directly into the
core graph builders, because that's no longer part of the public API.
However, I did include a couple new Context functions whose contract
is to produce a UI-oriented graph, and _for now_ those continue to
return the physical graph we use for those operations. There's no
exported API for generating the "validate" and "eval" graphs, because
neither is particularly interesting in its own right, and so
"terraform graph" no longer supports those graph types.
- terraform.NewContext no longer has the responsibility for collecting
all of the provider schemas up front. Instead, we wait until we need
them. However, that means that some of our error messages now have a
slightly different shape due to unwinding through a differently-shaped
call stack. As of this commit we also end up reloading the schemas
multiple times in some cases, which is functionally acceptable but
likely represents a performance regression. I intend to rework this to
use caching, but I'm saving that for a later commit because this one is
big enough already.
The proximal reason for this change is to resolve the chicken/egg problem
whereby there was previously no single point where we could apply "moved"
statements to the previous run state before creating a plan. With this
change in place, we can now do that as part of Context.Plan, prior to
forking the input state into the three separate state artifacts we use
during planning.
However, this is at least the third project in a row where the previous
API design led to piling more functionality into terraform.NewContext and
then working around the incorrect order of operations that produces, so
I intend that by paying the cost/risk of this large diff now we can in
turn reduce the cost/risk of future projects that relate to our main
workflow actions.
2021-08-24 14:06:38 -05:00
|
|
|
state := test.State
|
|
|
|
if state == nil {
|
|
|
|
state = states.NewState()
|
|
|
|
}
|
|
|
|
scope, diags := ctx.Eval(config, state, addrs.RootModuleInstance, &terraform.EvalOpts{})
|
2018-09-28 19:15:35 -05:00
|
|
|
if diags.HasErrors() {
|
|
|
|
t.Fatalf("failed to create scope: %s", diags.Err())
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
|
|
|
|
2022-02-04 09:32:06 -06:00
|
|
|
// Ensure that any console-only functions are available
|
|
|
|
scope.ConsoleMode = true
|
|
|
|
|
2016-11-14 00:04:21 -06:00
|
|
|
// Build the session
|
|
|
|
s := &Session{
|
2018-09-28 19:15:35 -05:00
|
|
|
Scope: scope,
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the inputs. We purposely don't use subtests here because
|
2018-09-28 19:15:35 -05:00
|
|
|
// the inputs don't represent subtests, but a sequence of stateful
|
2016-11-14 00:04:21 -06:00
|
|
|
// operations.
|
|
|
|
for _, input := range test.Inputs {
|
2018-09-28 19:15:35 -05:00
|
|
|
result, exit, diags := s.Handle(input.Input)
|
|
|
|
if exit != input.Exit {
|
|
|
|
t.Fatalf("incorrect 'exit' result %t; want %t", exit, input.Exit)
|
|
|
|
}
|
|
|
|
if (diags.HasErrors()) != input.Error {
|
|
|
|
t.Fatalf("%q: unexpected errors: %s", input.Input, diags.Err())
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
2018-09-28 19:15:35 -05:00
|
|
|
if diags.HasErrors() {
|
2016-11-14 00:04:21 -06:00
|
|
|
if input.ErrorContains != "" {
|
2018-09-28 19:15:35 -05:00
|
|
|
if !strings.Contains(diags.Err().Error(), input.ErrorContains) {
|
2016-11-14 00:04:21 -06:00
|
|
|
t.Fatalf(
|
2018-09-28 19:15:35 -05:00
|
|
|
"%q: diagnostics should contain: %q\n\n%s",
|
|
|
|
input.Input, input.ErrorContains, diags.Err(),
|
|
|
|
)
|
2016-11-14 00:04:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.Output != "" && result != input.Output {
|
|
|
|
t.Fatalf(
|
|
|
|
"%q: expected:\n\n%s\n\ngot:\n\n%s",
|
|
|
|
input.Input, input.Output, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.OutputContains != "" && !strings.Contains(result, input.OutputContains) {
|
|
|
|
t.Fatalf(
|
|
|
|
"%q: expected contains:\n\n%s\n\ngot:\n\n%s",
|
|
|
|
input.Input, input.OutputContains, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testSessionTest struct {
|
2018-09-28 19:15:35 -05:00
|
|
|
State *states.State // State to use
|
2019-06-30 02:38:36 -05:00
|
|
|
Module string // Module name in testdata to load
|
2016-11-14 00:04:21 -06:00
|
|
|
|
|
|
|
// Inputs are the list of test inputs that are run in order.
|
|
|
|
// Each input can test the output of each step.
|
|
|
|
Inputs []testSessionInput
|
|
|
|
}
|
|
|
|
|
|
|
|
// testSessionInput is a single input to test for a session.
|
|
|
|
type testSessionInput struct {
|
|
|
|
Input string // Input string
|
|
|
|
Output string // Exact output string to check
|
|
|
|
OutputContains string
|
|
|
|
Error bool // Error is true if error is expected
|
2018-09-28 19:15:35 -05:00
|
|
|
Exit bool // Exit is true if exiting is expected
|
2016-11-14 00:04:21 -06:00
|
|
|
ErrorContains string
|
|
|
|
}
|
2022-02-09 16:17:14 -06:00
|
|
|
|
|
|
|
func TestTypeString(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
Input cty.Value
|
|
|
|
Want string
|
|
|
|
}{
|
|
|
|
// Primititves
|
|
|
|
{
|
|
|
|
cty.StringVal("a"),
|
|
|
|
"string",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.NumberIntVal(42),
|
|
|
|
"number",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.BoolVal(true),
|
|
|
|
"bool",
|
|
|
|
},
|
|
|
|
// Collections
|
|
|
|
{
|
|
|
|
cty.EmptyObjectVal,
|
|
|
|
`object({})`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.EmptyTupleVal,
|
|
|
|
`tuple([])`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.ListValEmpty(cty.String),
|
|
|
|
`list(string)`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.MapValEmpty(cty.String),
|
|
|
|
`map(string)`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.SetValEmpty(cty.String),
|
|
|
|
`set(string)`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.ListVal([]cty.Value{cty.StringVal("a")}),
|
|
|
|
`list(string)`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.ListVal([]cty.Value{cty.ListVal([]cty.Value{cty.NumberIntVal(42)})}),
|
|
|
|
`list(list(number))`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.ListVal([]cty.Value{cty.MapValEmpty(cty.String)}),
|
|
|
|
`list(map(string))`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"foo": cty.StringVal("bar"),
|
|
|
|
})}),
|
|
|
|
"list(\n object({\n foo: string,\n }),\n)",
|
|
|
|
},
|
|
|
|
// Unknowns and Nulls
|
|
|
|
{
|
|
|
|
cty.UnknownVal(cty.String),
|
|
|
|
"string",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cty.NullVal(cty.Object(map[string]cty.Type{
|
|
|
|
"foo": cty.String,
|
|
|
|
})),
|
|
|
|
"object({\n foo: string,\n})",
|
|
|
|
},
|
|
|
|
{ // irrelevant marks do nothing
|
|
|
|
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"foo": cty.StringVal("bar").Mark("ignore me"),
|
|
|
|
})}),
|
|
|
|
"list(\n object({\n foo: string,\n }),\n)",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, test := range tests {
|
|
|
|
got := typeString(test.Input.Type())
|
|
|
|
if got != test.Want {
|
|
|
|
t.Errorf("wrong result:\n%s", cmp.Diff(got, test.Want))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|