2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +00:00
restic/tree_test.go

53 lines
863 B
Go
Raw Normal View History

2014-09-23 20:39:12 +00:00
package khepri_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
var testFiles = []struct {
name string
content []byte
}{
{"foo", []byte("bar")},
{"bar/foo2", []byte("bar2")},
{"bar/bla/blubb", []byte("This is just a test!\n")},
}
// prepareDir creates a temporary directory and returns it.
func prepareDir(t *testing.T) string {
2014-09-23 20:39:12 +00:00
tempdir, err := ioutil.TempDir("", "khepri-test-")
ok(t, err)
for _, test := range testFiles {
file := filepath.Join(tempdir, test.name)
dir := filepath.Dir(file)
if dir != "." {
ok(t, os.MkdirAll(dir, 0755))
}
f, err := os.Create(file)
defer func() {
ok(t, f.Close())
}()
ok(t, err)
_, err = f.Write(test.content)
ok(t, err)
}
return tempdir
}
func TestTree(t *testing.T) {
dir := prepareDir(t)
2014-09-23 20:39:12 +00:00
defer func() {
if *testCleanup {
ok(t, os.RemoveAll(dir))
}
}()
}