Merge pull request #10300 from hashicorp/jbardin/state-backup-ext

Remove extra dot from state backup file
This commit is contained in:
Mitchell Hashimoto 2016-11-23 08:26:30 -08:00 committed by GitHub
commit 4865be6b5b
2 changed files with 17 additions and 1 deletions

View File

@ -28,7 +28,7 @@ func (c *StateMeta) State(m *Meta) (state.State, error) {
// Determine the backup path. stateOutPath is set to the resulting
// file where state is written (cached in the case of remote state)
backupPath := fmt.Sprintf(
"%s.%d.%s",
"%s.%d%s",
m.stateOutPath,
time.Now().UTC().Unix(),
DefaultBackupExtension)

View File

@ -2,8 +2,11 @@ package command
import (
"path/filepath"
"regexp"
"sort"
"testing"
"github.com/hashicorp/terraform/state"
)
// testStateBackups returns the list of backups in order of creation
@ -20,3 +23,16 @@ func testStateBackups(t *testing.T, dir string) []string {
return list
}
func TestStateDefaultBackupExtension(t *testing.T) {
s, err := (&StateMeta{}).State(&Meta{})
if err != nil {
t.Fatal(err)
}
backupPath := s.(*state.BackupState).Path
match := regexp.MustCompile(`terraform\.tfstate\.\d+\.backup$`).MatchString
if !match(backupPath) {
t.Fatal("Bad backup path:", backupPath)
}
}