Skip to content
Snippets Groups Projects
Select Git revision
  • master
1 result

sourcelink.html

Blame
  • repository_restic_test.go 5.04 KiB
    package tabacco
    
    import (
    	"bytes"
    	"context"
    	"io/ioutil"
    	"os"
    	"os/exec"
    	"path/filepath"
    	"testing"
    
    	"git.autistici.org/ai3/tools/tabacco/jobs"
    )
    
    // Create a temporary directory with two subdirs: 'data', for
    // the test backup data, and 'repo' to store the (remote)
    // repository. Populate 'data' with two tiny files.
    //
    // nolint
    func createTempDirWithData(t *testing.T) string {
    	tmpdir, err := ioutil.TempDir("", "")
    	if err != nil {
    		t.Fatal(err)
    	}
    	for _, d := range []string{"data", "repo", "restore"} {
    		os.Mkdir(filepath.Join(tmpdir, d), 0700)
    	}
    	ioutil.WriteFile(
    		filepath.Join(tmpdir, "data", "file1"),
    		[]byte("this is file number one."),
    		0600,
    	)
    	ioutil.WriteFile(
    		filepath.Join(tmpdir, "data", "file2"),
    		[]byte("this is file number two."),
    		0600,
    	)
    	return tmpdir
    }
    
    // nolint: gocyclo
    func runResticTest(t *testing.T, tmpdir string, source *SourceSpec, restorePattern string, checkFn func(testing.TB, string)) {
    	// Check that we can actually run restic.
    	resticVersion, err := getResticVersion("restic")
    	if err != nil {
    		t.Skip("can't find restic: ", err)
    	}
    	if resticVersion.LessThan(resticMinGoodVersion) {
    		t.Skip("restic version ", resticVersion,
    			" is older than the minimum supported version ",
    			resticMinGoodVersion)
    	}
    
    	// Temporary cache dir.
    	cacheDir, err := ioutil.TempDir("", "")
    	if err != nil {
    		t.Fatal(err)
    	}
    	defer os.RemoveAll(cacheDir)
    
    	store := &dummyMetadataStore{}
    
    	repoSpec := RepositorySpec{
    		Name: "main",
    		Type: "restic",
    		Params: map[string]interface{}{
    			"uri":       tmpdir + "/repo",
    			"password":  "testpass",
    			"cache_dir": cacheDir,
    		},