Remove extra dot from state backup file

The state subcommand was adding an extra dot to the backup file
This commit is contained in:
James Bardin 2016-11-22 15:39:00 -05:00
parent 2cd4344682
commit bf20db688c
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 // Determine the backup path. stateOutPath is set to the resulting
// file where state is written (cached in the case of remote state) // file where state is written (cached in the case of remote state)
backupPath := fmt.Sprintf( backupPath := fmt.Sprintf(
"%s.%d.%s", "%s.%d%s",
m.stateOutPath, m.stateOutPath,
time.Now().UTC().Unix(), time.Now().UTC().Unix(),
DefaultBackupExtension) DefaultBackupExtension)

View File

@ -2,8 +2,11 @@ package command
import ( import (
"path/filepath" "path/filepath"
"regexp"
"sort" "sort"
"testing" "testing"
"github.com/hashicorp/terraform/state"
) )
// testStateBackups returns the list of backups in order of creation // testStateBackups returns the list of backups in order of creation
@ -20,3 +23,16 @@ func testStateBackups(t *testing.T, dir string) []string {
return list 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)
}
}