opentofu/internal/command/state_test.go
Martin Atkins f40800b3a4 Move states/ to internal/states/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

42 lines
935 B
Go

package command
import (
"path/filepath"
"regexp"
"sort"
"testing"
"github.com/hashicorp/terraform/internal/states/statemgr"
)
// 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.(*statemgr.Filesystem).BackupPath()
match := regexp.MustCompile(`terraform\.tfstate\.\d+\.backup$`).MatchString
if !match(backupPath) {
t.Fatal("Bad backup path:", backupPath)
}
}