mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: Add more tests for cases we felt weren't well covered
This commit is contained in:
parent
e8ac16b2df
commit
71918efd96
@ -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")
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,3 @@
|
||||
variable "in" {}
|
||||
|
||||
aws_instance "foo" {}
|
@ -0,0 +1,5 @@
|
||||
output "data" {
|
||||
value = "foo"
|
||||
}
|
||||
|
||||
aws_instance "foo" {}
|
@ -0,0 +1,8 @@
|
||||
module "foo" {
|
||||
source = "./foo"
|
||||
}
|
||||
|
||||
module "bar" {
|
||||
source = "./bar"
|
||||
in = "${module.foo.data}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user