core: Fix TestContext2Input

This test was previously not setting InputModeVarUnset, causing us to
overwrite the "amis" map that _is_ already set. This worked before because
we used to treat the empty result as an empty map and then merge it with
the given value, but since we no longer do that merging behavior we were
ending up with an empty map after input.

Since the intent of this test is to see that the "foo" variable gets
populated by input, here we add InputModeVarUnset which then matches how
the input walk is triggered by the "real" codepath in the local backend.

This also includes some updates to make the test fixture v0.12-idiomatic
(applied after it was seen to work with the old fixture) and to properly
handle the "diags" return value from the various context methods.
This commit is contained in:
Martin Atkins 2018-05-24 18:02:43 -07:00
parent 1b55f09891
commit 74873838e0
2 changed files with 18 additions and 24 deletions

View File

@ -24,16 +24,11 @@ func TestContext2Input(t *testing.T) {
}, },
), ),
Variables: InputValues{ Variables: InputValues{
"foo": &InputValue{
Value: cty.StringVal("us-west-2"),
SourceType: ValueFromCaller,
},
"amis": &InputValue{ "amis": &InputValue{
Value: cty.ListVal([]cty.Value{ Value: cty.MapVal(map[string]cty.Value{
cty.MapVal(map[string]cty.Value{
"us-east-1": cty.StringVal("override"), "us-east-1": cty.StringVal("override"),
}), }),
}), SourceType: ValueFromCaller,
}, },
}, },
UIInput: input, UIInput: input,
@ -43,17 +38,17 @@ func TestContext2Input(t *testing.T) {
"var.foo": "us-east-1", "var.foo": "us-east-1",
} }
if err := ctx.Input(InputModeStd); err != nil { if diags := ctx.Input(InputModeStd | InputModeVarUnset); diags.HasErrors() {
t.Fatalf("err: %s", err) t.Fatalf("input errors: %s", diags.Err())
} }
if _, err := ctx.Plan(); err != nil { if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("err: %s", err) t.Fatalf("plan errors: %s", diags.Err())
} }
state, err := ctx.Apply() state, diags := ctx.Apply()
if err != nil { if diags.HasErrors() {
t.Fatalf("err: %s", err) t.Fatalf("apply errors: %s", diags.Err())
} }
actual := strings.TrimSpace(state.String()) actual := strings.TrimSpace(state.String())

View File

@ -1,6 +1,5 @@
variable "amis" { variable "amis" {
default = { default = {
us-east-1 = "foo"
us-west-2 = "bar" us-west-2 = "bar"
} }
} }
@ -13,10 +12,10 @@ variable "foo" {}
resource "aws_instance" "foo" { resource "aws_instance" "foo" {
num = "2" num = "2"
bar = "${var.bar}" bar = var.bar
} }
resource "aws_instance" "bar" { resource "aws_instance" "bar" {
foo = "${var.foo}" foo = var.foo
bar = "${lookup(var.amis, var.foo)}" bar = var.amis[var.foo]
} }