command: Remove tests related to legacy remote state migrations, etc

We no longer support legacy remote state, so the behaviors these tests
were covering are no longer present.
This commit is contained in:
Martin Atkins 2018-10-14 07:58:43 -07:00
parent aafa3ced07
commit 53bb3f57e6
1 changed files with 0 additions and 777 deletions

View File

@ -1441,783 +1441,6 @@ func TestMetaBackend_configuredUnsetCopy(t *testing.T) {
}
}
// Saved backend state matching config, with legacy
func TestMetaBackend_configuredUnchangedLegacy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unchanged-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "configured" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatalf("err: %s", err)
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state matching config, with legacy
func TestMetaBackend_configuredUnchangedLegacyCopy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unchanged-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Setup the meta
m := testMetaBackend(t, nil)
m.forceInitCopy = true
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "backend-unchanged-with-legacy" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state, new config, legacy remote state
func TestMetaBackend_configuredChangedLegacy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-changed-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no", "no"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state != nil {
t.Fatal("state should be nil")
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state-2.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state, new config, legacy remote state
func TestMetaBackend_configuredChangedLegacyCopyBackend(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-changed-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"yes", "no"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "configured" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state-2.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state, new config, legacy remote state
func TestMetaBackend_configuredChangedLegacyCopyLegacy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-changed-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no", "yes", "yes"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "legacy" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state-2.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state, new config, legacy remote state
func TestMetaBackend_configuredChangedLegacyCopyBoth(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-changed-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"yes", "yes", "yes", "yes"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "legacy" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths don't exist
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open("local-state-2.tfstate")
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify no local state
if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatal("file should not exist")
}
// Verify no local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatal("file should not exist")
}
}
// Saved backend state, unset config, legacy remote state
func TestMetaBackend_configuredUnsetWithLegacyNoCopy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unset-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no", "no"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state != nil {
t.Fatal("state should be nil")
}
// Verify the default paths dont exist since we had no state
if !isEmptyState(DefaultStateFilename) {
t.Fatal("state should be empty")
}
// Verify a backup doesn't exist
if !isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backup should be empty")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open(DefaultStateFilename)
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
}
// Saved backend state, unset config, legacy remote state
func TestMetaBackend_configuredUnsetWithLegacyCopyBackend(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unset-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"yes", "no"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "backend" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths exist
if isEmptyState(DefaultStateFilename) {
t.Fatalf("default state was empty")
}
// Verify a backup doesn't exist
if !isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backupstate should be empty")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open(DefaultStateFilename)
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify a local backup
if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backup is empty")
}
}
// Saved backend state, unset config, legacy remote state
func TestMetaBackend_configuredUnsetWithLegacyCopyLegacy(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unset-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"no", "yes", "yes"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "legacy" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths exist
if isEmptyState(DefaultStateFilename) {
t.Fatalf("default state was empty")
}
// Verify a backup doesn't exist
if !isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backupstate should be empty")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open(DefaultStateFilename)
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify a local backup
if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backup is empty")
}
}
// Saved backend state, unset config, legacy remote state
func TestMetaBackend_configuredUnsetWithLegacyCopyBoth(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
copy.CopyDir(testFixturePath("backend-unset-with-legacy"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
// Ask input
defer testInteractiveInput(t, []string{"yes", "yes", "yes", "yes"})()
// Setup the meta
m := testMetaBackend(t, nil)
// Get the backend
b, diags := m.Backend(&BackendOpts{Init: true})
if diags.HasErrors() {
t.Fatal(diags.Err())
}
// Check the state
s, err := b.StateMgr(backend.DefaultStateName)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "legacy" {
t.Fatalf("bad: %#v", state)
}
// Verify the default paths exist
if isEmptyState(DefaultStateFilename) {
t.Fatal("state is empty")
}
// Verify a backup exists
if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backup is empty")
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err)
}
// Verify the state is where we expect
{
f, err := os.Open(DefaultStateFilename)
if err != nil {
t.Fatalf("err: %s", err)
}
actual, err := statefile.Read(f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
assertStateHasMarker(t, actual.State, mark)
}
// Verify a local backup
if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatal("backup is empty")
}
}
// A plan that has uses the local backend
func TestMetaBackend_planLocal(t *testing.T) {
// Create a temporary working directory that is empty