github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/state_test.go (about)

     1  package command
     2  
     3  import (
     4  	"path/filepath"
     5  	"regexp"
     6  	"sort"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/terraform/internal/states/statemgr"
    10  )
    11  
    12  // testStateBackups returns the list of backups in order of creation
    13  // (oldest first) in the given directory.
    14  func testStateBackups(t *testing.T, dir string) []string {
    15  	// Find all the backups
    16  	list, err := filepath.Glob(filepath.Join(dir, "*"+DefaultBackupExtension))
    17  	if err != nil {
    18  		t.Fatalf("err: %s", err)
    19  	}
    20  
    21  	// Sort them which will put them naturally in the right order
    22  	sort.Strings(list)
    23  
    24  	return list
    25  }
    26  
    27  func TestStateDefaultBackupExtension(t *testing.T) {
    28  	testCwd(t)
    29  
    30  	s, err := (&StateMeta{}).State()
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	backupPath := s.(*statemgr.Filesystem).BackupPath()
    36  	match := regexp.MustCompile(`terraform\.tfstate\.\d+\.backup$`).MatchString
    37  	if !match(backupPath) {
    38  		t.Fatal("Bad backup path:", backupPath)
    39  	}
    40  }