mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
test planfile may need to have a specific lineage
In order to test applying a plan from an existing state, we need to be able to inject the state meta into the planfile.
This commit is contained in:
@@ -710,7 +710,6 @@ func TestApply_plan(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApply_plan_backup(t *testing.T) {
|
||||
planPath := applyFixturePlanFile(t)
|
||||
statePath := testTempFile(t)
|
||||
backupPath := testTempFile(t)
|
||||
|
||||
@@ -724,11 +723,17 @@ func TestApply_plan_backup(t *testing.T) {
|
||||
}
|
||||
|
||||
// create a state file that needs to be backed up
|
||||
err := statemgr.NewFilesystem(statePath).WriteState(states.NewState())
|
||||
fs := statemgr.NewFilesystem(statePath)
|
||||
fs.StateSnapshotMeta()
|
||||
err := fs.WriteState(states.NewState())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// the plan file must contain the metadata from the prior state to be
|
||||
// backed up
|
||||
planPath := applyFixturePlanFileMatchState(t, fs.StateSnapshotMeta())
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"-backup", backupPath,
|
||||
@@ -2280,6 +2285,13 @@ func applyFixtureProvider() *terraform.MockProvider {
|
||||
// a single change to create the test_instance.foo that is included in the
|
||||
// "apply" test fixture, returning the location of that plan file.
|
||||
func applyFixturePlanFile(t *testing.T) string {
|
||||
return applyFixturePlanFileMatchState(t, statemgr.SnapshotMeta{})
|
||||
}
|
||||
|
||||
// applyFixturePlanFileMatchState creates a planfile like applyFixturePlanFile,
|
||||
// but inserts the state meta information if that plan must match a preexisting
|
||||
// state.
|
||||
func applyFixturePlanFileMatchState(t *testing.T, stateMeta statemgr.SnapshotMeta) string {
|
||||
_, snap := testModuleWithSnapshot(t, "apply")
|
||||
plannedVal := cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.UnknownVal(cty.String),
|
||||
@@ -2310,11 +2322,12 @@ func applyFixturePlanFile(t *testing.T) string {
|
||||
After: plannedValRaw,
|
||||
},
|
||||
})
|
||||
return testPlanFile(
|
||||
return testPlanFileMatchState(
|
||||
t,
|
||||
snap,
|
||||
states.NewState(),
|
||||
plan,
|
||||
stateMeta,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user