core: test coverage around map key regression

tests to cover the HCL-level issue fixed in
https://github.com/hashicorp/hcl/pull/65
This commit is contained in:
Paul Hinze 2015-11-24 15:57:38 -06:00
parent bd23ab35bf
commit 0e277a6714
3 changed files with 67 additions and 1 deletions

View File

@ -35,6 +35,12 @@ func TestFlagKV(t *testing.T) {
false,
},
{
"map.key=foo",
map[string]string{"map.key": "foo"},
false,
},
{
"key",
nil,
@ -84,6 +90,12 @@ foo = "bar"
map[string]string{"foo": "bar"},
false,
},
{
`map.key = "foo"`,
map[string]string{"map.key": "foo"},
false,
},
}
path := testTempFile(t)
@ -96,7 +108,7 @@ foo = "bar"
f := new(FlagKVFile)
err := f.Set(path)
if err != nil != tc.Error {
t.Fatalf("bad error. Input: %#v", tc.Input)
t.Fatalf("bad error. Input: %#v, err: %s", tc.Input, err)
}
actual := map[string]string(*f)

View File

@ -807,6 +807,46 @@ func TestContext2Apply_countVariable(t *testing.T) {
}
}
func TestContext2Apply_mapVariableOverride(t *testing.T) {
m := testModule(t, "apply-map-var-override")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
Variables: map[string]string{
"images.us-west-2": "overridden",
},
})
if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(`
aws_instance.bar:
ID = foo
ami = overridden
type = aws_instance
aws_instance.foo:
ID = foo
ami = image-1234
type = aws_instance
`)
if actual != expected {
t.Fatalf("got: \n%s\nexpected: \n%s", actual, expected)
}
}
func TestContext2Apply_module(t *testing.T) {
m := testModule(t, "apply-module")
p := testProvider("aws")

View File

@ -0,0 +1,14 @@
variable "images" {
default = {
us-east-1 = "image-1234"
us-west-2 = "image-4567"
}
}
resource "aws_instance" "foo" {
ami = "${lookup(var.images, "us-east-1")}"
}
resource "aws_instance" "bar" {
ami = "${lookup(var.images, "us-west-2")}"
}