config: eval HEL as long as the result changes [GH-2909]
This commit is contained in:
parent
54de9057ba
commit
f223be15cd
|
@ -118,9 +118,15 @@ func (w *interpolationWalker) Primitive(v reflect.Value) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// If the AST we got is just a literal string value, then we ignore it
|
||||
if _, ok := astRoot.(*ast.LiteralNode); ok {
|
||||
return nil
|
||||
// If the AST we got is just a literal string value with the same
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
if w.ContextF != nil {
|
||||
|
|
|
@ -24,6 +24,14 @@ func TestEval(t *testing.T) {
|
|||
ast.TypeString,
|
||||
},
|
||||
|
||||
{
|
||||
"foo $${bar}",
|
||||
nil,
|
||||
false,
|
||||
"foo ${bar}",
|
||||
ast.TypeString,
|
||||
},
|
||||
|
||||
{
|
||||
"foo ${bar}",
|
||||
&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) {
|
||||
raw1 := map[string]interface{}{
|
||||
"foo": "${var.foo}",
|
||||
|
|
Loading…
Reference in New Issue