Skip to content

Commit

Permalink
Merge pull request #4053 from hashicorp/phinze/map-key-test-coverage
Browse files Browse the repository at this point in the history
core: test coverage around map key regression
  • Loading branch information
jen20 committed Nov 25, 2015
2 parents 2304c26 + 0e277a6 commit 8ae0f6a
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 8ae0f6a

Please sign in to comment.