config: tests for HIL-to-HCL2 value shimming
This commit is contained in:
parent
bbf9725134
commit
34e9de605c
|
@ -94,3 +94,86 @@ func TestConfigValueFromHCL2(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHCL2ValueFromConfigValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
Input interface{}
|
||||
Want cty.Value
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
cty.NullVal(cty.DynamicPseudoType),
|
||||
},
|
||||
{
|
||||
UnknownVariableValue,
|
||||
cty.DynamicVal,
|
||||
},
|
||||
{
|
||||
true,
|
||||
cty.True,
|
||||
},
|
||||
{
|
||||
false,
|
||||
cty.False,
|
||||
},
|
||||
{
|
||||
int(12),
|
||||
cty.NumberIntVal(12),
|
||||
},
|
||||
{
|
||||
int(0),
|
||||
cty.Zero,
|
||||
},
|
||||
{
|
||||
float64(12.5),
|
||||
cty.NumberFloatVal(12.5),
|
||||
},
|
||||
{
|
||||
"hello world",
|
||||
cty.StringVal("hello world"),
|
||||
},
|
||||
{
|
||||
"O\u0308", // decomposed letter + diacritic
|
||||
cty.StringVal("\u00D6"), // NFC-normalized on entry into cty
|
||||
},
|
||||
{
|
||||
[]interface{}{},
|
||||
cty.EmptyTupleVal,
|
||||
},
|
||||
{
|
||||
[]interface{}(nil),
|
||||
cty.EmptyTupleVal,
|
||||
},
|
||||
{
|
||||
[]interface{}{"hello", "world"},
|
||||
cty.TupleVal([]cty.Value{cty.StringVal("hello"), cty.StringVal("world")}),
|
||||
},
|
||||
{
|
||||
map[string]interface{}{},
|
||||
cty.EmptyObjectVal,
|
||||
},
|
||||
{
|
||||
map[string]interface{}(nil),
|
||||
cty.EmptyObjectVal,
|
||||
},
|
||||
{
|
||||
map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"bar": "baz",
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
"bar": cty.StringVal("baz"),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(fmt.Sprintf("%#v", test.Input), func(t *testing.T) {
|
||||
got := hcl2ValueFromConfigValue(test.Input)
|
||||
if !got.RawEquals(test.Want) {
|
||||
t.Errorf("wrong result\ninput: %#v\ngot: %#v\nwant: %#v", test.Input, got, test.Want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue