mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
33ba6774e0
In order to use a backend for the state commands, we need an initialized meta. Use a single Meta instance rather than temporary ones to make sure the backends are initialized properly.
42 lines
906 B
Go
42 lines
906 B
Go
package command
|
|
|
|
import (
|
|
"path/filepath"
|
|
"regexp"
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/state"
|
|
)
|
|
|
|
// testStateBackups returns the list of backups in order of creation
|
|
// (oldest first) in the given directory.
|
|
func testStateBackups(t *testing.T, dir string) []string {
|
|
// Find all the backups
|
|
list, err := filepath.Glob(filepath.Join(dir, "*"+DefaultBackupExtension))
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
// Sort them which will put them naturally in the right order
|
|
sort.Strings(list)
|
|
|
|
return list
|
|
}
|
|
|
|
func TestStateDefaultBackupExtension(t *testing.T) {
|
|
tmp, cwd := testCwd(t)
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
s, err := (&StateMeta{}).State()
|
|
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)
|
|
}
|
|
}
|