opentofu/terraform/eval_output_test.go
James Bardin a26446931b validate depends_on for outputs
If depends_on is allowed for outputs, we should validate that the
expressions are valid. Since outputs are always evaluated, and
validation is just done by this evaluation, we can check the
depends_on validation during evaluation too.
2020-06-16 12:40:48 -04:00

60 lines
1.2 KiB
Go

package terraform
import (
"testing"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/addrs"
"github.com/zclconf/go-cty/cty"
)
func TestEvalWriteMapOutput(t *testing.T) {
ctx := new(MockEvalContext)
ctx.StateState = states.NewState().SyncWrapper()
cases := []struct {
name string
val cty.Value
err bool
}{
{
// Eval should recognize a single map in a slice, and collapse it
// into the map value
"single-map",
cty.MapVal(map[string]cty.Value{
"a": cty.StringVal("b"),
}),
false,
},
{
// we can't apply a multi-valued map to a variable, so this should error
"multi-map",
cty.ListVal([]cty.Value{
cty.MapVal(map[string]cty.Value{
"a": cty.StringVal("b"),
}),
cty.MapVal(map[string]cty.Value{
"c": cty.StringVal("d"),
}),
}),
true,
},
}
for _, tc := range cases {
evalNode := &EvalWriteOutput{
Config: &configs.Output{},
Addr: addrs.OutputValue{Name: tc.name},
}
ctx.EvaluateExprResult = tc.val
t.Run(tc.name, func(t *testing.T) {
_, err := evalNode.Eval(ctx)
if err != nil && !tc.err {
t.Fatal(err)
}
})
}
}