Add test for RawMap

Ensure that RawMap() returns an identical copy, and not a reference to
the original map.
This commit is contained in:
James Bardin 2016-08-31 14:00:59 -04:00
parent 632c16c212
commit 14138fc449
1 changed files with 24 additions and 0 deletions

View File

@ -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")
}
}