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