config: eval HEL as long as the result changes [GH-2909]
This commit is contained in:
parent
54de9057ba
commit
f223be15cd
|
@ -118,10 +118,16 @@ func (w *interpolationWalker) Primitive(v reflect.Value) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the AST we got is just a literal string value, then we ignore it
|
// If the AST we got is just a literal string value with the same
|
||||||
if _, ok := astRoot.(*ast.LiteralNode); ok {
|
// value then we ignore it. We have to check if its the same value
|
||||||
|
// because it is possible to input a string, get out a string, and
|
||||||
|
// have it be different. For example: "foo-$${bar}" turns into
|
||||||
|
// "foo-${bar}"
|
||||||
|
if n, ok := astRoot.(*ast.LiteralNode); ok {
|
||||||
|
if s, ok := n.Value.(string); ok && s == v.String() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if w.ContextF != nil {
|
if w.ContextF != nil {
|
||||||
w.ContextF(w.loc, astRoot)
|
w.ContextF(w.loc, astRoot)
|
||||||
|
|
|
@ -24,6 +24,14 @@ func TestEval(t *testing.T) {
|
||||||
ast.TypeString,
|
ast.TypeString,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"foo $${bar}",
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
"foo ${bar}",
|
||||||
|
ast.TypeString,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"foo ${bar}",
|
"foo ${bar}",
|
||||||
&ast.BasicScope{
|
&ast.BasicScope{
|
||||||
|
|
|
@ -114,6 +114,38 @@ func TestRawConfig_double(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRawConfigInterpolate_escaped(t *testing.T) {
|
||||||
|
raw := map[string]interface{}{
|
||||||
|
"foo": "bar-$${baz}",
|
||||||
|
}
|
||||||
|
|
||||||
|
rc, err := NewRawConfig(raw)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Before interpolate, Config() should be the raw
|
||||||
|
if !reflect.DeepEqual(rc.Config(), raw) {
|
||||||
|
t.Fatalf("bad: %#v", rc.Config())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rc.Interpolate(nil); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := rc.Config()
|
||||||
|
expected := map[string]interface{}{
|
||||||
|
"foo": "bar-${baz}",
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Fatalf("bad: %#v", actual)
|
||||||
|
}
|
||||||
|
if len(rc.UnknownKeys()) != 0 {
|
||||||
|
t.Fatalf("bad: %#v", rc.UnknownKeys())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRawConfig_merge(t *testing.T) {
|
func TestRawConfig_merge(t *testing.T) {
|
||||||
raw1 := map[string]interface{}{
|
raw1 := map[string]interface{}{
|
||||||
"foo": "${var.foo}",
|
"foo": "${var.foo}",
|
||||||
|
|
Loading…
Reference in New Issue