mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
config: test nested function calls
This commit is contained in:
parent
7dfd4f5a3c
commit
bff5c09164
@ -49,6 +49,39 @@ func TestExprParse(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"lookup(var.foo, lookup(var.baz, var.bar))",
|
||||
&FunctionInterpolation{
|
||||
Func: nil, // Funcs["lookup"]
|
||||
Args: []Interpolation{
|
||||
&VariableInterpolation{
|
||||
Variable: &UserVariable{
|
||||
Name: "foo",
|
||||
key: "var.foo",
|
||||
},
|
||||
},
|
||||
&FunctionInterpolation{
|
||||
Func: nil, // Funcs["lookup"]
|
||||
Args: []Interpolation{
|
||||
&VariableInterpolation{
|
||||
Variable: &UserVariable{
|
||||
Name: "baz",
|
||||
key: "var.baz",
|
||||
},
|
||||
},
|
||||
&VariableInterpolation{
|
||||
Variable: &UserVariable{
|
||||
Name: "bar",
|
||||
key: "var.bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
@ -59,8 +92,22 @@ func TestExprParse(t *testing.T) {
|
||||
|
||||
// This is jank, but reflect.DeepEqual never has functions
|
||||
// being the same.
|
||||
if f, ok := actual.(*FunctionInterpolation); ok {
|
||||
f.Func = nil
|
||||
f, ok := actual.(*FunctionInterpolation)
|
||||
if ok {
|
||||
fs := make([]*FunctionInterpolation, 1)
|
||||
fs[0] = f
|
||||
for len(fs) > 0 {
|
||||
f := fs[0]
|
||||
fs = fs[1:]
|
||||
|
||||
f.Func = nil
|
||||
for _, a := range f.Args {
|
||||
f, ok := a.(*FunctionInterpolation)
|
||||
if ok {
|
||||
fs = append(fs, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, tc.Result) {
|
||||
|
@ -98,6 +98,10 @@ func (i *FunctionInterpolation) Interpolate(
|
||||
return i.Func(vs, args...)
|
||||
}
|
||||
|
||||
func (i *FunctionInterpolation) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *i)
|
||||
}
|
||||
|
||||
func (i *FunctionInterpolation) Variables() map[string]InterpolatedVariable {
|
||||
result := make(map[string]InterpolatedVariable)
|
||||
for _, a := range i.Args {
|
||||
@ -130,6 +134,10 @@ func (i *VariableInterpolation) Interpolate(
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (i *VariableInterpolation) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *i)
|
||||
}
|
||||
|
||||
func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable {
|
||||
return map[string]InterpolatedVariable{i.Variable.FullKey(): i.Variable}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user