mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 03:18:55 +00:00
commit
fcb769fa3b
1
Vagrantfile
vendored
1
Vagrantfile
vendored
@ -85,6 +85,7 @@ end
|
|||||||
Vagrant.configure(2) do |config|
|
Vagrant.configure(2) do |config|
|
||||||
# use rsync to copy content to the folder
|
# use rsync to copy content to the folder
|
||||||
config.vm.synced_folder ".", "/vagrant/go/src/github.com/restic/restic", :type => "rsync"
|
config.vm.synced_folder ".", "/vagrant/go/src/github.com/restic/restic", :type => "rsync"
|
||||||
|
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||||
|
|
||||||
# fix permissions on synced folder
|
# fix permissions on synced folder
|
||||||
config.vm.provision "fix perms", :type => :shell, :inline => fix_perms
|
config.vm.provision "fix perms", :type => :shell, :inline => fix_perms
|
||||||
|
@ -57,7 +57,7 @@ func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan s
|
|||||||
cmd := &CmdMount{global: &global, ready: ready, done: done}
|
cmd := &CmdMount{global: &global, ready: ready, done: done}
|
||||||
OK(t, cmd.Execute([]string{dir}))
|
OK(t, cmd.Execute([]string{dir}))
|
||||||
if TestCleanup {
|
if TestCleanup {
|
||||||
OK(t, os.RemoveAll(dir))
|
RemoveAll(t, dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ func TestMount(t *testing.T) {
|
|||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
// We remove the mountpoint now to check that cmdMount creates it
|
// We remove the mountpoint now to check that cmdMount creates it
|
||||||
OK(t, os.RemoveAll(mountpoint))
|
RemoveAll(t, mountpoint)
|
||||||
|
|
||||||
ready := make(chan struct{}, 1)
|
ready := make(chan struct{}, 1)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -183,7 +183,7 @@ func cleanupTempdir(t testing.TB, tempdir string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
OK(t, os.RemoveAll(tempdir))
|
RemoveAll(t, tempdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// withTestEnvironment creates a test environment and calls f with it. After f has
|
// withTestEnvironment creates a test environment and calls f with it. After f has
|
||||||
@ -214,5 +214,5 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions))
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
OK(t, os.RemoveAll(tempdir))
|
RemoveAll(t, tempdir)
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package crypto_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/restic/chunker"
|
"github.com/restic/chunker"
|
||||||
@ -50,10 +50,7 @@ func TestSmallBuffer(t *testing.T) {
|
|||||||
|
|
||||||
size := 600
|
size := 600
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
f, err := os.Open("/dev/urandom")
|
_, err := io.ReadFull(rand.Reader, data)
|
||||||
OK(t, err)
|
|
||||||
|
|
||||||
_, err = io.ReadFull(f, data)
|
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
ciphertext := make([]byte, size/2)
|
ciphertext := make([]byte, size/2)
|
||||||
@ -75,10 +72,7 @@ func TestSameBuffer(t *testing.T) {
|
|||||||
|
|
||||||
size := 600
|
size := 600
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
f, err := os.Open("/dev/urandom")
|
_, err := io.ReadFull(rand.Reader, data)
|
||||||
OK(t, err)
|
|
||||||
|
|
||||||
_, err = io.ReadFull(f, data)
|
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
ciphertext := make([]byte, 0, size+crypto.Extension)
|
ciphertext := make([]byte, 0, size+crypto.Extension)
|
||||||
@ -124,10 +118,7 @@ func TestLargeEncrypt(t *testing.T) {
|
|||||||
|
|
||||||
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
|
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
f, err := os.Open("/dev/urandom")
|
_, err := io.ReadFull(rand.Reader, data)
|
||||||
OK(t, err)
|
|
||||||
|
|
||||||
_, err = io.ReadFull(f, data)
|
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data)
|
ciphertext, err := crypto.Encrypt(k, make([]byte, size+crypto.Extension), data)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// +build !openbsd
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package fuse
|
package fuse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -109,7 +109,7 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if TestCleanup {
|
if TestCleanup {
|
||||||
OK(t, os.RemoveAll(tempdir))
|
RemoveAll(t, tempdir)
|
||||||
} else {
|
} else {
|
||||||
t.Logf("leaving tempdir at %v", tempdir)
|
t.Logf("leaving tempdir at %v", tempdir)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ func Equals(tb testing.TB, exp, act interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseID parses s as a backend.ID and panics if that fails.
|
||||||
func ParseID(s string) backend.ID {
|
func ParseID(s string) backend.ID {
|
||||||
id, err := backend.ParseID(s)
|
id, err := backend.ParseID(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,19 +89,18 @@ func RandomReader(seed, size int) *bytes.Reader {
|
|||||||
|
|
||||||
// SetupTarTestFixture extracts the tarFile to outputDir.
|
// SetupTarTestFixture extracts the tarFile to outputDir.
|
||||||
func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
|
func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) {
|
||||||
err := System("sh", "-c", `(cd "$1" && tar xzf - ) < "$2"`,
|
f, err := os.Open(tarFile)
|
||||||
"sh", outputDir, tarFile)
|
defer f.Close()
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// System runs the command and returns the exit code. Output is passed on to
|
cmd := exec.Command("tar", "xzf", "-")
|
||||||
// stdout/stderr.
|
cmd.Dir = outputDir
|
||||||
func System(command string, args ...string) error {
|
|
||||||
cmd := exec.Command(command, args...)
|
cmd.Stdin = f
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
return cmd.Run()
|
OK(t, cmd.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithTestEnvironment creates a test environment, extracts the repository
|
// WithTestEnvironment creates a test environment, extracts the repository
|
||||||
@ -124,7 +124,7 @@ func WithTestEnvironment(t testing.TB, repoFixture string, f func(repodir string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
OK(t, os.RemoveAll(tempdir))
|
RemoveAll(t, tempdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenLocalRepo opens the local repository located at dir.
|
// OpenLocalRepo opens the local repository located at dir.
|
||||||
@ -138,3 +138,31 @@ func OpenLocalRepo(t testing.TB, dir string) *repository.Repository {
|
|||||||
|
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isFile(fi os.FileInfo) bool {
|
||||||
|
return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetReadOnly recursively resets the read-only flag recursively for dir.
|
||||||
|
// This is mainly used for tests on Windows, which is unable to delete a file
|
||||||
|
// set read-only.
|
||||||
|
func ResetReadOnly(t testing.TB, dir string) {
|
||||||
|
OK(t, filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
|
||||||
|
if fi.IsDir() {
|
||||||
|
return os.Chmod(path, 0777)
|
||||||
|
}
|
||||||
|
|
||||||
|
if isFile(fi) {
|
||||||
|
return os.Chmod(path, 0666)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveAll recursively resets the read-only flag of all files and dirs and
|
||||||
|
// afterwards uses os.RemoveAll() to remove the path.
|
||||||
|
func RemoveAll(t testing.TB, path string) {
|
||||||
|
ResetReadOnly(t, path)
|
||||||
|
OK(t, os.RemoveAll(path))
|
||||||
|
}
|
||||||
|
@ -50,7 +50,7 @@ func TestTree(t *testing.T) {
|
|||||||
dir := createTempDir(t)
|
dir := createTempDir(t)
|
||||||
defer func() {
|
defer func() {
|
||||||
if TestCleanup {
|
if TestCleanup {
|
||||||
OK(t, os.RemoveAll(dir))
|
RemoveAll(t, dir)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user