terraform: add test for diff var changing

This commit is contained in:
Mitchell Hashimoto 2014-07-24 20:16:15 -07:00
parent 3726d092e7
commit 79a9dfce4a
3 changed files with 72 additions and 0 deletions

View File

@ -1464,6 +1464,55 @@ func TestContextPlan_destroy(t *testing.T) {
}
}
func TestContextPlan_diffVar(t *testing.T) {
c := testConfig(t, "plan-diffvar")
p := testProvider("aws")
s := &State{
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
ID: "bar",
Attributes: map[string]string{
"num": "2",
},
},
},
}
ctx := testContext(t, &ContextOpts{
Config: c,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: s,
})
p.DiffFn = func(
s *ResourceState, c *ResourceConfig) (*ResourceDiff, error) {
if s.ID != "bar" {
return testDiffFn(s, c)
}
return &ResourceDiff{
Attributes: map[string]*ResourceAttrDiff{
"num": &ResourceAttrDiff{
Old: "2",
New: "3",
},
},
}, nil
}
plan, err := ctx.Plan(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanDiffVarStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_hook(t *testing.T) {
c := testConfig(t, "plan-good")
h := new(MockHook)

View File

@ -378,6 +378,22 @@ aws_instance.two:
ID = baz
`
const testTerraformPlanDiffVarStr = `
DIFF:
CREATE: aws_instance.bar
num: "" => "3"
type: "" => "aws_instance"
UPDATE: aws_instance.foo
num: "2" => "3"
STATE:
aws_instance.foo:
ID = bar
num = 2
`
const testTerraformPlanEmptyStr = `
DIFF:

View File

@ -0,0 +1,7 @@
resource "aws_instance" "foo" {
num = "2"
}
resource "aws_instance" "bar" {
num = "${aws_instance.foo.num}"
}