Ensure that backend tests check for data in state

Test should not simply check for the existence of a file for state, but
make sure that file also contains data.
This commit is contained in:
James Bardin 2017-01-30 17:38:32 -05:00
parent 7590154974
commit 39ca4fa2f8
1 changed files with 34 additions and 34 deletions

View File

@ -49,7 +49,7 @@ func TestMetaBackend_emptyDir(t *testing.T) {
// Verify no backend state was made // Verify no backend state was made
if !isEmptyState(filepath.Join(m.DataDir(), DefaultStateFilename)) { if !isEmptyState(filepath.Join(m.DataDir(), DefaultStateFilename)) {
t.Fatal("backend state shoudl be empty") t.Fatal("backend state should be empty")
} }
} }
@ -125,8 +125,8 @@ func TestMetaBackend_emptyWithDefaultState(t *testing.T) {
} }
// Verify a backup was made since we're modifying a pre-existing state // Verify a backup was made since we're modifying a pre-existing state
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup state should not be empty")
} }
} }
@ -195,8 +195,8 @@ func TestMetaBackend_emptyWithExplicitState(t *testing.T) {
} }
// Verify a backup was made since we're modifying a pre-existing state // Verify a backup was made since we're modifying a pre-existing state
if _, err := os.Stat(statePath + DefaultBackupExtension); err != nil { if isEmptyState(statePath + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup state should not be empty")
} }
} }
@ -311,13 +311,13 @@ func TestMetaBackend_configureNew(t *testing.T) {
} }
// Verify the default paths don't exist // Verify the default paths don't exist
if !isEmptyState(DefaultStateFilename) { if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatalf("state should not exist") t.Fatalf("err: %s", err)
} }
// Verify a backup doesn't exist // Verify a backup doesn't exist
if !isEmptyState(DefaultStateFilename + DefaultBackupExtension) { if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatalf("backup state should not exist") t.Fatalf("err: %s", err)
} }
} }
@ -1100,8 +1100,8 @@ func TestMetaBackend_configuredUnsetCopy(t *testing.T) {
} }
// Verify a backup since it wasn't empty to start // Verify a backup since it wasn't empty to start
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -1903,8 +1903,8 @@ func TestMetaBackend_configuredUnsetWithLegacyCopyBackend(t *testing.T) {
} }
// Verify a local backup // Verify a local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -2001,8 +2001,8 @@ func TestMetaBackend_configuredUnsetWithLegacyCopyLegacy(t *testing.T) {
} }
// Verify a local backup // Verify a local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -2043,13 +2043,13 @@ func TestMetaBackend_configuredUnsetWithLegacyCopyBoth(t *testing.T) {
} }
// Verify the default paths exist // Verify the default paths exist
if _, err := os.Stat(DefaultStateFilename); err != nil { if isEmptyState(DefaultStateFilename) {
t.Fatalf("err: %s", err) t.Fatal("state is empty")
} }
// Verify a backup exists // Verify a backup exists
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
// Verify we have no configured backend/legacy // Verify we have no configured backend/legacy
@ -2099,8 +2099,8 @@ func TestMetaBackend_configuredUnsetWithLegacyCopyBoth(t *testing.T) {
} }
// Verify a local backup // Verify a local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -2276,8 +2276,8 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) {
} }
// Verify we have a backup // Verify we have a backup
if _, err := os.Stat(statePath + DefaultBackupExtension); err != nil { if isEmptyState(statePath + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -2321,8 +2321,8 @@ func TestMetaBackend_planLocalMatch(t *testing.T) {
} }
// Verify the default path // Verify the default path
if _, err := os.Stat(DefaultStateFilename); err != nil { if isEmptyState(DefaultStateFilename) {
t.Fatalf("err: %s", err) t.Fatal("state is empty")
} }
// Verify a backup exists // Verify a backup exists
@ -2362,8 +2362,8 @@ func TestMetaBackend_planLocalMatch(t *testing.T) {
} }
// Verify local backup // Verify local backup
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err != nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
} }
@ -2521,13 +2521,13 @@ func TestMetaBackend_planBackendEmptyDir(t *testing.T) {
} }
// Verify the default path // Verify the default path
if _, err := os.Stat(DefaultStateFilename); err == nil { if isEmptyState(DefaultStateFilename) {
t.Fatalf("err: %s", err) t.Fatal("state is empty")
} }
// Verify a backup exists // Verify a backup exists
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil { if isEmptyState(DefaultStateFilename + DefaultBackupExtension) {
t.Fatalf("err: %s", err) t.Fatal("backup is empty")
} }
// Verify we have no configured backend/legacy // Verify we have no configured backend/legacy
@ -2622,12 +2622,12 @@ func TestMetaBackend_planBackendMatch(t *testing.T) {
t.Fatalf("bad: %#v", state) t.Fatalf("bad: %#v", state)
} }
// Verify the default path // Verify the default path exists
if _, err := os.Stat(DefaultStateFilename); err == nil { if _, err := os.Stat(DefaultStateFilename); err == nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
// Verify a backup exists // Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil { if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -2720,7 +2720,7 @@ func TestMetaBackend_planBackendMismatchLineage(t *testing.T) {
t.Fatalf("bad: %#v", actual) t.Fatalf("bad: %#v", actual)
} }
// Verify a backup doesn't exists // Verify a backup doesn't exist
if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil { if _, err := os.Stat(DefaultStateFilename + DefaultBackupExtension); err == nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }