From 9a6c8490a0033f16daee60a770164a87b76d4890 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Sep 2014 15:27:56 -0700 Subject: [PATCH] terraform: Updating tests for modules --- terraform/context_test.go | 16 ++++++------ terraform/graph_test.go | 52 +++++++++++---------------------------- 2 files changed, 23 insertions(+), 45 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index 7129bde58e..c92e30b40b 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -583,7 +583,7 @@ func TestContextApply(t *testing.T) { } func TestContextApply_createBeforeDestroy(t *testing.T) { - c := testConfig(t, "apply-good-create-before") + m := testModule(t, "apply-good-create-before") p := testProvider("aws") p.ApplyFn = testApplyFn p.DiffFn = testDiffFn @@ -606,7 +606,7 @@ func TestContextApply_createBeforeDestroy(t *testing.T) { }, } ctx := testContext(t, &ContextOpts{ - Config: c, + Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), }, @@ -933,7 +933,7 @@ func TestContextApply_provisionerFail(t *testing.T) { } func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { - c := testConfig(t, "apply-provisioner-fail-create-before") + m := testModule(t, "apply-provisioner-fail-create-before") p := testProvider("aws") pr := testProvisioner() p.ApplyFn = testApplyFn @@ -961,7 +961,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { }, } ctx := testContext(t, &ContextOpts{ - Config: c, + Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), }, @@ -988,7 +988,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { } func TestContextApply_error_createBeforeDestroy(t *testing.T) { - c := testConfig(t, "apply-error-create-before") + m := testModule(t, "apply-error-create-before") p := testProvider("aws") state := &State{ Modules: []*ModuleState{ @@ -1009,7 +1009,7 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) { }, } ctx := testContext(t, &ContextOpts{ - Config: c, + Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), }, @@ -1037,7 +1037,7 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) { } func TestContextApply_errorDestroy_createBeforeDestroy(t *testing.T) { - c := testConfig(t, "apply-error-create-before") + m := testModule(t, "apply-error-create-before") p := testProvider("aws") state := &State{ Modules: []*ModuleState{ @@ -1058,7 +1058,7 @@ func TestContextApply_errorDestroy_createBeforeDestroy(t *testing.T) { }, } ctx := testContext(t, &ContextOpts{ - Config: c, + Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), }, diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 94a357376e..461b49d01f 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -653,16 +653,21 @@ func TestGraphAddDiff_module(t *testing.T) { } func TestGraphAddDiff_createBeforeDestroy(t *testing.T) { - config := testConfig(t, "graph-diff-create-before") + m := testModule(t, "graph-diff-create-before") diff := &Diff{ - Resources: map[string]*InstanceDiff{ - "aws_instance.bar": &InstanceDiff{ - Destroy: true, - Attributes: map[string]*ResourceAttrDiff{ - "ami": &ResourceAttrDiff{ - Old: "abc", - New: "xyz", - RequiresNew: true, + Modules: []*ModuleDiff{ + &ModuleDiff{ + Path: rootModulePath, + Resources: map[string]*InstanceDiff{ + "aws_instance.bar": &InstanceDiff{ + Destroy: true, + Attributes: map[string]*ResourceAttrDiff{ + "ami": &ResourceAttrDiff{ + Old: "abc", + New: "xyz", + RequiresNew: true, + }, + }, }, }, }, @@ -690,7 +695,7 @@ func TestGraphAddDiff_createBeforeDestroy(t *testing.T) { diffHash := checksumStruct(t, diff) g, err := Graph(&GraphOpts{ - Config: config, + Module: m, Diff: diff, State: state, }) @@ -722,33 +727,6 @@ func TestGraphAddDiff_createBeforeDestroy(t *testing.T) { } } -func TestGraphInitState(t *testing.T) { - config := testConfig(t, "graph-basic") - state := &State{ - Modules: []*ModuleState{ - &ModuleState{ - Path: rootModulePath, - Resources: map[string]*InstanceDiff{ - "aws_instance.foo": &InstanceDiff{ - Destroy: true, - }, - }, - }, - }, - } - - g, err := Graph(&GraphOpts{Module: m, Diff: diff}) - if err != nil { - t.Fatalf("err: %s", err) - } - - actual := strings.TrimSpace(g.String()) - expected := strings.TrimSpace(testTerraformGraphDiffModuleStr) - if actual != expected { - t.Fatalf("bad:\n\n%s", actual) - } -} - func TestGraphAddDiff_moduleDestroy(t *testing.T) { m := testModule(t, "graph-diff-module") diff := &Diff{