From 14b371d533ad0cbd41229453756431bdc9c99c51 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 2 Dec 2016 13:25:32 -0500 Subject: [PATCH] config: validate that RawConfig.Copy doesn't copy the interpolated values --- config/raw_config_test.go | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/config/raw_config_test.go b/config/raw_config_test.go index 4def6a77a..c6f7b496d 100644 --- a/config/raw_config_test.go +++ b/config/raw_config_test.go @@ -382,6 +382,59 @@ func TestRawConfig_sliceIndexLoss(t *testing.T) { } } +func TestRawConfigCopy(t *testing.T) { + raw := map[string]interface{}{ + "foo": "${var.bar}", + } + + rc, err := NewRawConfig(raw) + if err != nil { + t.Fatalf("err: %s", err) + } + + rc.Key = "foo" + if rc.Value() != "${var.bar}" { + t.Fatalf("err: %#v", rc.Value()) + } + + // Interpolate the first one + vars := map[string]ast.Variable{ + "var.bar": ast.Variable{ + Value: "baz", + Type: ast.TypeString, + }, + } + if err := rc.Interpolate(vars); err != nil { + t.Fatalf("err: %s", err) + } + + if rc.Value() != "baz" { + t.Fatalf("bad: %#v", rc.Value()) + } + + // Copy and interpolate + { + rc2 := rc.Copy() + if rc2.Value() != "${var.bar}" { + t.Fatalf("err: %#v", rc2.Value()) + } + + vars := map[string]ast.Variable{ + "var.bar": ast.Variable{ + Value: "qux", + Type: ast.TypeString, + }, + } + if err := rc2.Interpolate(vars); err != nil { + t.Fatalf("err: %s", err) + } + + if rc2.Value() != "qux" { + t.Fatalf("bad: %#v", rc2.Value()) + } + } +} + func TestRawConfigValue(t *testing.T) { raw := map[string]interface{}{ "foo": "${var.bar}",