github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-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/muratcelep/terraform/not-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  	tmp, cwd := testCwd(t)
    29  	defer testFixCwd(t, tmp, cwd)
    30  
    31  	s, err := (&StateMeta{}).State()
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	backupPath := s.(*statemgr.Filesystem).BackupPath()
    37  	match := regexp.MustCompile(`terraform\.tfstate\.\d+\.backup$`).MatchString
    38  	if !match(backupPath) {
    39  		t.Fatal("Bad backup path:", backupPath)
    40  	}
    41  }