terraform: Add more tests for cases we felt weren't well covered

This commit is contained in:
Mitchell Hashimoto 2014-12-16 15:59:26 -08:00
parent e8ac16b2df
commit 71918efd96
5 changed files with 126 additions and 0 deletions

View File

@ -2861,6 +2861,35 @@ func TestContextPlan(t *testing.T) {
}
}
func TestContextPlan_emptyDiff(t *testing.T) {
m := testModule(t, "plan-empty")
p := testProvider("aws")
p.DiffFn = func(
info *InstanceInfo,
s *InstanceState,
c *ResourceConfig) (*InstanceDiff, error) {
return nil, nil
}
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
plan, err := ctx.Plan(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanEmptyStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_minimal(t *testing.T) {
m := testModule(t, "plan-empty")
p := testProvider("aws")

View File

@ -786,6 +786,77 @@ func TestGraphAddDiff_module_depends(t *testing.T) {
}
}
func TestGraphAddDiff_moduleDependsModule(t *testing.T) {
m := testModule(t, "graph-diff-module-dep-module")
diff := &Diff{
Modules: []*ModuleDiff{
&ModuleDiff{
Path: []string{"root"},
Destroy: true,
},
&ModuleDiff{
Path: []string{"root", "foo"},
Destroy: true,
Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{
Destroy: true,
},
},
},
&ModuleDiff{
Path: []string{"root", "bar"},
Destroy: true,
Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{
Destroy: true,
},
},
},
},
}
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "foo"},
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
&ModuleState{
Path: []string{"root", "bar"},
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
Dependencies: []string{
"module.foo",
},
},
},
}
g, err := Graph(&GraphOpts{Module: m, Diff: diff, State: state})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTerraformGraphDiffModuleDependsModuleStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraphAddDiff_createBeforeDestroy(t *testing.T) {
m := testModule(t, "graph-diff-create-before")
diff := &Diff{
@ -1345,6 +1416,16 @@ root
root -> module.orphan
`
const testTerraformGraphDiffModuleDependsModuleStr = `
root: root
module.bar
module.foo
module.foo -> module.bar
root
root -> module.bar
root -> module.foo
`
const testTerraformGraphModulesStr = `
root: root
aws_instance.web

View File

@ -0,0 +1,3 @@
variable "in" {}
aws_instance "foo" {}

View File

@ -0,0 +1,5 @@
output "data" {
value = "foo"
}
aws_instance "foo" {}

View File

@ -0,0 +1,8 @@
module "foo" {
source = "./foo"
}
module "bar" {
source = "./bar"
in = "${module.foo.data}"
}