From 14138fc4491e9a4a795648483286a2cdcdbb9b69 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 31 Aug 2016 14:00:59 -0400 Subject: [PATCH] Add test for RawMap Ensure that RawMap() returns an identical copy, and not a reference to the original map. --- config/raw_config_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/config/raw_config_test.go b/config/raw_config_test.go index d6901d3c4..e718ca994 100644 --- a/config/raw_config_test.go +++ b/config/raw_config_test.go @@ -342,3 +342,27 @@ func TestRawConfig_implGob(t *testing.T) { var _ gob.GobDecoder = new(RawConfig) var _ gob.GobEncoder = new(RawConfig) } + +// verify that RawMap returns a identical copy +func TestNewRawConfig_rawMap(t *testing.T) { + raw := map[string]interface{}{ + "foo": "${var.bar}", + "bar": `${file("boom.txt")}`, + } + + rc, err := NewRawConfig(raw) + if err != nil { + t.Fatalf("err: %s", err) + } + + rawCopy := rc.RawMap() + if !reflect.DeepEqual(raw, rawCopy) { + t.Fatalf("bad: %#v", rawCopy) + } + + // make sure they aren't the same map + raw["test"] = "value" + if reflect.DeepEqual(raw, rawCopy) { + t.Fatal("RawMap() didn't return a copy") + } +}