From 11d073f7d489ba1b7c0c2cede45a43b1e9d57231 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Mar 2015 21:39:48 -0800 Subject: [PATCH] terraform: test the increase from one case --- terraform/context_test.go | 58 +++++++++++++++++++++++++++++++++++++ terraform/terraform_test.go | 26 +++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/terraform/context_test.go b/terraform/context_test.go index 06de7312d..aaeda9159 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -829,6 +829,64 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { } } +// https://github.com/PeoplePerHour/terraform/pull/11 +// +// This tests a case where both a "resource" and "resource.0" are in +// the state file, which apparently is a reasonable backwards compatibility +// concern found in the above 3rd party repo. +func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { + m := testModule(t, "plan-count-inc") + p := testProvider("aws") + p.DiffFn = testDiffFn + s := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "foo", + "type": "aws_instance", + }, + }, + }, + "aws_instance.foo.0": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "foo", + "type": "aws_instance", + }, + }, + }, + }, + }, + }, + } + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: s, + }) + + plan, err := ctx.Plan(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(plan.String()) + expected := strings.TrimSpace(testTerraformPlanCountIncreaseFromOneCorruptedStr) + if actual != expected { + t.Fatalf("bad:\n%s", actual) + } +} + func TestContext2Plan_destroy(t *testing.T) { m := testModule(t, "plan-destroy") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 815a1dd98..4070475c0 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -829,6 +829,32 @@ aws_instance.foo.0: type = aws_instance ` +const testTerraformPlanCountIncreaseFromOneCorruptedStr = ` +DIFF: + +CREATE: aws_instance.bar + foo: "" => "bar" + type: "" => "aws_instance" +DESTROY: aws_instance.foo +CREATE: aws_instance.foo.1 + foo: "" => "foo" + type: "" => "aws_instance" +CREATE: aws_instance.foo.2 + foo: "" => "foo" + type: "" => "aws_instance" + +STATE: + +aws_instance.foo: + ID = bar + foo = foo + type = aws_instance +aws_instance.foo.0: + ID = bar + foo = foo + type = aws_instance +` + const testTerraformPlanDestroyStr = ` DIFF: