Skip to content

Commit

Permalink
core: test coverage around map key regression
Browse files Browse the repository at this point in the history
tests to cover the HCL-level issue fixed in
hashicorp/hcl#65
  • Loading branch information
phinze committed Nov 24, 2015
1 parent bd23ab3 commit 0e277a6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
14 changes: 13 additions & 1 deletion command/flag_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestFlagKV(t *testing.T) {
false,
},

{
"map.key=foo",
map[string]string{"map.key": "foo"},
false,
},

{
"key",
nil,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions terraform/test-fixtures/apply-map-var-override/main.tf
Original file line number Diff line number Diff line change
@@ -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")}"
}

0 comments on commit 0e277a6

Please sign in to comment.