terraform: Updating tests for modules

This commit is contained in:
Armon Dadgar 2014-09-29 15:27:56 -07:00
parent bce9b664d8
commit 9a6c8490a0
2 changed files with 23 additions and 45 deletions

View File

@ -583,7 +583,7 @@ func TestContextApply(t *testing.T) {
} }
func TestContextApply_createBeforeDestroy(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 := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
@ -606,7 +606,7 @@ func TestContextApply_createBeforeDestroy(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -933,7 +933,7 @@ func TestContextApply_provisionerFail(t *testing.T) {
} }
func TestContextApply_provisionerFail_createBeforeDestroy(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") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
@ -961,7 +961,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -988,7 +988,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) {
} }
func TestContextApply_error_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") p := testProvider("aws")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -1009,7 +1009,7 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1037,7 +1037,7 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) {
} }
func TestContextApply_errorDestroy_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") p := testProvider("aws")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -1058,7 +1058,7 @@ func TestContextApply_errorDestroy_createBeforeDestroy(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },

View File

@ -653,8 +653,11 @@ func TestGraphAddDiff_module(t *testing.T) {
} }
func TestGraphAddDiff_createBeforeDestroy(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{ diff := &Diff{
Modules: []*ModuleDiff{
&ModuleDiff{
Path: rootModulePath,
Resources: map[string]*InstanceDiff{ Resources: map[string]*InstanceDiff{
"aws_instance.bar": &InstanceDiff{ "aws_instance.bar": &InstanceDiff{
Destroy: true, Destroy: true,
@ -667,6 +670,8 @@ func TestGraphAddDiff_createBeforeDestroy(t *testing.T) {
}, },
}, },
}, },
},
},
} }
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -690,7 +695,7 @@ func TestGraphAddDiff_createBeforeDestroy(t *testing.T) {
diffHash := checksumStruct(t, diff) diffHash := checksumStruct(t, diff)
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: config, Module: m,
Diff: diff, Diff: diff,
State: state, 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) { func TestGraphAddDiff_moduleDestroy(t *testing.T) {
m := testModule(t, "graph-diff-module") m := testModule(t, "graph-diff-module")
diff := &Diff{ diff := &Diff{