Merge pull request #4053 from hashicorp/phinze/map-key-test-coverage
core: test coverage around map key regression
This commit is contained in:
commit
8ae0f6a05e
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")}"
|
||||
}
|
Loading…
Reference in New Issue