forked from TrueCloudLab/restic
Add test for --repository-file
This commit is contained in:
parent
97f7855de3
commit
61035d68bc
1 changed files with 33 additions and 0 deletions
|
@ -2,8 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/test"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,3 +29,33 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadRepo(t *testing.T) {
|
||||||
|
tempDir, cleanup := test.TempDir(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
// test --repo option
|
||||||
|
var opts GlobalOptions
|
||||||
|
opts.Repo = tempDir
|
||||||
|
repo, err := ReadRepo(opts)
|
||||||
|
rtest.OK(t, err)
|
||||||
|
rtest.Equals(t, tempDir, repo)
|
||||||
|
|
||||||
|
// test --repository-file option
|
||||||
|
foo := filepath.Join(tempDir, "foo")
|
||||||
|
err = ioutil.WriteFile(foo, []byte(tempDir+"\n"), 0666)
|
||||||
|
rtest.OK(t, err)
|
||||||
|
|
||||||
|
var opts2 GlobalOptions
|
||||||
|
opts2.RepositoryFile = foo
|
||||||
|
repo, err = ReadRepo(opts2)
|
||||||
|
rtest.OK(t, err)
|
||||||
|
rtest.Equals(t, tempDir, repo)
|
||||||
|
|
||||||
|
var opts3 GlobalOptions
|
||||||
|
opts3.RepositoryFile = foo + "-invalid"
|
||||||
|
repo, err = ReadRepo(opts3)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("must not read repository path from invalid file path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue