create failing test cases for remote lineage issue
Some remote backend would fail on `-state push -force`, or `workspace new -state` because of a new strict lineage check in remote.State.
This commit is contained in:
parent
18d71f273e
commit
16e8e405c7
|
@ -5,6 +5,8 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/backend/remote-state/inmem"
|
||||
"github.com/hashicorp/terraform/helper/copy"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
|
@ -190,3 +192,56 @@ func TestStatePush_serialOlder(t *testing.T) {
|
|||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatePush_forceRemoteState(t *testing.T) {
|
||||
td := tempDir(t)
|
||||
copy.CopyDir(testFixturePath("inmem-backend"), td)
|
||||
defer os.RemoveAll(td)
|
||||
defer testChdir(t, td)()
|
||||
defer inmem.Reset()
|
||||
|
||||
s := terraform.NewState()
|
||||
statePath := testStateFile(t, s)
|
||||
|
||||
// init the backend
|
||||
ui := new(cli.MockUi)
|
||||
initCmd := &InitCommand{
|
||||
Meta: Meta{Ui: ui},
|
||||
}
|
||||
if code := initCmd.Run([]string{}); code != 0 {
|
||||
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
// create a new workspace
|
||||
ui = new(cli.MockUi)
|
||||
newCmd := &WorkspaceNewCommand{
|
||||
Meta: Meta{Ui: ui},
|
||||
}
|
||||
if code := newCmd.Run([]string{"test"}); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
|
||||
}
|
||||
|
||||
// put a dummy state in place, so we have something to force
|
||||
b := backend.TestBackendConfig(t, inmem.New(), nil)
|
||||
sMgr, err := b.State("test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := sMgr.WriteState(terraform.NewState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := sMgr.PersistState(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// push our local state to that new workspace
|
||||
ui = new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
Meta: Meta{Ui: ui},
|
||||
}
|
||||
|
||||
args := []string{"-force", statePath}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
terraform {
|
||||
backend "inmem" {}
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/backend/remote-state/inmem"
|
||||
"github.com/hashicorp/terraform/helper/copy"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
|
@ -57,6 +58,7 @@ func TestUnlock_inmemBackend(t *testing.T) {
|
|||
copy.CopyDir(testFixturePath("backend-inmem-locked"), td)
|
||||
defer os.RemoveAll(td)
|
||||
defer testChdir(t, td)()
|
||||
defer inmem.Reset()
|
||||
|
||||
// init backend
|
||||
ui := new(cli.MockUi)
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/backend/local"
|
||||
"github.com/hashicorp/terraform/backend/remote-state/inmem"
|
||||
"github.com/hashicorp/terraform/helper/copy"
|
||||
"github.com/hashicorp/terraform/state"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/cli"
|
||||
|
@ -211,9 +213,19 @@ func TestWorkspace_createInvalid(t *testing.T) {
|
|||
|
||||
func TestWorkspace_createWithState(t *testing.T) {
|
||||
td := tempDir(t)
|
||||
os.MkdirAll(td, 0755)
|
||||
copy.CopyDir(testFixturePath("inmem-backend"), td)
|
||||
defer os.RemoveAll(td)
|
||||
defer testChdir(t, td)()
|
||||
defer inmem.Reset()
|
||||
|
||||
// init the backend
|
||||
ui := new(cli.MockUi)
|
||||
initCmd := &InitCommand{
|
||||
Meta: Meta{Ui: ui},
|
||||
}
|
||||
if code := initCmd.Run([]string{}); code != 0 {
|
||||
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
// create a non-empty state
|
||||
originalState := &terraform.State{
|
||||
|
@ -238,7 +250,7 @@ func TestWorkspace_createWithState(t *testing.T) {
|
|||
}
|
||||
|
||||
args := []string{"-state", "test.tfstate", "test"}
|
||||
ui := new(cli.MockUi)
|
||||
ui = new(cli.MockUi)
|
||||
newCmd := &WorkspaceNewCommand{
|
||||
Meta: Meta{Ui: ui},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue