mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
4a21b763aa
After the refactoring to integrate HCL2 many of the tests were no longer using correct types, attribute names, etc. This is a bulk update of all of the tests to make them compile again, with minimal changes otherwise. Although the tests now compile, many of them do not yet pass. The tests will be gradually repaired in subsequent commits, as we continue to complete the refactoring and retrofit work.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package terraform
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestEvalWriteMapOutput(t *testing.T) {
|
|
ctx := new(MockEvalContext)
|
|
ctx.StateState = NewState()
|
|
ctx.StateLock = new(sync.RWMutex)
|
|
|
|
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{
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|