mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
a26446931b
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.
60 lines
1.2 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|