From e976d6e787fff2c5baf9f04217137d17df78b54e Mon Sep 17 00:00:00 2001 From: James Nugent Date: Thu, 10 Dec 2015 13:09:57 -0500 Subject: [PATCH] testing: Use a copy of pre-destroy state in destroy check In the acceptance testing framework, it is neccessary to provide a copy of the state _before_ the destroy is applied to the check in order that it can loop over resources to verify their destruction. This patch makes a deep copy of the state prior to applying test steps which have the Destroy option set and then passes that to the destroy check. --- helper/resource/testing.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 18a40553b..db74d8d2e 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -247,6 +247,11 @@ func testStep( log.Printf("[WARN] Test: Step plan: %s", p) } + // We need to keep a copy of the state prior to destroying + // such that destroy steps can verify their behaviour in the check + // function + stateBeforeApplication := state.DeepCopy() + // Apply! state, err = ctx.Apply() if err != nil { @@ -255,8 +260,14 @@ func testStep( // Check! Excitement! if step.Check != nil { - if err := step.Check(state); err != nil { - return state, fmt.Errorf("Check failed: %s", err) + if step.Destroy { + if err := step.Check(stateBeforeApplication); err != nil { + return state, fmt.Errorf("Check failed: %s", err) + } + } else { + if err := step.Check(state); err != nil { + return state, fmt.Errorf("Check failed: %s", err) + } } }