mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21: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.
98 lines
2.0 KiB
Go
98 lines
2.0 KiB
Go
package terraform
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestVariables(t *testing.T) {
|
|
cases := map[string]struct {
|
|
Module string
|
|
Override map[string]cty.Value
|
|
Expected map[string]cty.Value
|
|
}{
|
|
"config only": {
|
|
"vars-basic",
|
|
nil,
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("foo"),
|
|
"b": cty.ListValEmpty(cty.String),
|
|
"c": cty.MapValEmpty(cty.String),
|
|
},
|
|
},
|
|
|
|
"override": {
|
|
"vars-basic",
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("bar"),
|
|
"b": cty.ListVal([]cty.Value{
|
|
cty.StringVal("foo"),
|
|
cty.StringVal("bar"),
|
|
}),
|
|
"c": cty.MapVal(map[string]cty.Value{
|
|
"foo": cty.StringVal("bar"),
|
|
}),
|
|
},
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("bar"),
|
|
"b": cty.ListVal([]cty.Value{
|
|
cty.StringVal("foo"),
|
|
cty.StringVal("bar"),
|
|
}),
|
|
"c": cty.MapVal(map[string]cty.Value{
|
|
"foo": cty.StringVal("bar"),
|
|
}),
|
|
},
|
|
},
|
|
|
|
"bools: config only": {
|
|
"vars-basic-bool",
|
|
nil,
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("1"),
|
|
"b": cty.StringVal("0"),
|
|
},
|
|
},
|
|
|
|
"bools: override with string": {
|
|
"vars-basic-bool",
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("foo"),
|
|
"b": cty.StringVal("bar"),
|
|
},
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("foo"),
|
|
"b": cty.StringVal("bar"),
|
|
},
|
|
},
|
|
|
|
"bools: override with bool": {
|
|
"vars-basic-bool",
|
|
map[string]cty.Value{
|
|
"a": cty.False,
|
|
"b": cty.True,
|
|
},
|
|
map[string]cty.Value{
|
|
"a": cty.StringVal("0"),
|
|
"b": cty.StringVal("1"),
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, tc := range cases {
|
|
// Wrapped in a func so we can get defers to work
|
|
t.Run(name, func(t *testing.T) {
|
|
m := testModule(t, tc.Module)
|
|
fromConfig := DefaultVariableValues(m.Module.Variables)
|
|
overrides := InputValuesFromCaller(tc.Override)
|
|
actual := fromConfig.Override(overrides)
|
|
|
|
if !reflect.DeepEqual(actual, tc.Expected) {
|
|
t.Fatalf("%s\n\nexpected: %#v\n\ngot: %#v", name, tc.Expected, actual)
|
|
}
|
|
})
|
|
}
|
|
}
|