terraform: Testing duplicate delete issue

This commit is contained in:
Armon Dadgar 2014-11-18 15:38:54 -08:00
parent 01db1ff8bd
commit e29e364c89
1 changed files with 88 additions and 1 deletions

View File

@ -2656,7 +2656,7 @@ func TestContextApply_createBefore_depends(t *testing.T) {
// Test that things were managed _in the right order_ // Test that things were managed _in the right order_
order := h.States order := h.States
diffs := h.Diffs diffs := h.Diffs
if order[0].ID != "bar" || diffs[0].Destroy { if order[0].ID != "" || diffs[0].Destroy {
t.Fatalf("should create new instance first: %#v", order) t.Fatalf("should create new instance first: %#v", order)
} }
@ -2669,6 +2669,93 @@ func TestContextApply_createBefore_depends(t *testing.T) {
} }
} }
func TestContextApply_singleDestroy(t *testing.T) {
m := testModule(t, "apply-depends-create-before")
h := new(HookRecordApplyOrder)
p := testProvider("aws")
invokeCount := 0
p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) {
invokeCount++
switch invokeCount {
case 1:
if d.Destroy {
t.Fatalf("should not destroy")
}
if s.ID != "" {
t.Fatalf("should not have ID")
}
case 2:
if d.Destroy {
t.Fatalf("should not destroy")
}
if s.ID != "baz" {
t.Fatalf("should have id")
}
case 3:
if !d.Destroy {
t.Fatalf("should destroy")
}
if s.ID == "" {
t.Fatalf("should have ID")
}
default:
t.Fatalf("bad invoke count %d", invokeCount)
}
return testApplyFn(info, s, d)
}
p.DiffFn = testDiffFn
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.web": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"require_new": "ami-old",
},
},
},
"aws_instance.lb": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "baz",
Attributes: map[string]string{
"instance": "bar",
},
},
},
},
},
},
}
ctx := testContext(t, &ContextOpts{
Module: m,
Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: state,
})
if _, err := ctx.Plan(nil); err != nil {
t.Fatalf("err: %s", err)
}
h.Active = true
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
if invokeCount != 3 {
t.Fatalf("bad: %d", invokeCount)
}
}
func TestContextPlan(t *testing.T) { func TestContextPlan(t *testing.T) {
m := testModule(t, "plan-good") m := testModule(t, "plan-good")
p := testProvider("aws") p := testProvider("aws")