mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-24 17:15:40 +00:00
test: Allow using an environment variable to override the test dir
Some build systems may not permit writing to . during build, so allow that path to be overridden with an environment variable.
This commit is contained in:
parent
93776cd69e
commit
cb1fb5dded
3 changed files with 22 additions and 7 deletions
|
@ -13,9 +13,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXattr(t *testing.T) {
|
func TestXattr(t *testing.T) {
|
||||||
// a bit dirty to create/destory a directory in cwd, but often /tmp is
|
testDir, present := os.LookupEnv("MTREE_TESTDIR")
|
||||||
// mounted tmpfs and doesn't support xattrs
|
if present == false {
|
||||||
dir, err := ioutil.TempDir(".", "test.xattrs.")
|
// a bit dirty to create/destory a directory in cwd,
|
||||||
|
// but often /tmp is mounted tmpfs and doesn't support
|
||||||
|
// xattrs
|
||||||
|
testDir = "."
|
||||||
|
}
|
||||||
|
dir, err := ioutil.TempDir(testDir, "test.xattrs.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
12
tar_test.go
12
tar_test.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -78,11 +79,16 @@ func TestTar(t *testing.T) {
|
||||||
t.Fatal("expected a DirectoryHierarchy struct, but got nil")
|
t.Fatal("expected a DirectoryHierarchy struct, but got nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
fh, err = os.Create("./testdata/test.mtree")
|
testDir, present := os.LookupEnv("MTREE_TESTDIR")
|
||||||
|
if present == false {
|
||||||
|
testDir = "."
|
||||||
|
}
|
||||||
|
testPath := filepath.Join(testDir, "test.mtree")
|
||||||
|
fh, err = os.Create(testPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.Remove("./testdata/test.mtree")
|
defer os.Remove(testPath)
|
||||||
|
|
||||||
// put output of tar walk into test.mtree
|
// put output of tar walk into test.mtree
|
||||||
_, err = tdh.WriteTo(fh)
|
_, err = tdh.WriteTo(fh)
|
||||||
|
@ -92,7 +98,7 @@ func TestTar(t *testing.T) {
|
||||||
fh.Close()
|
fh.Close()
|
||||||
|
|
||||||
// now simulate gomtree -T testdata/test.tar -f testdata/test.mtree
|
// now simulate gomtree -T testdata/test.tar -f testdata/test.mtree
|
||||||
fh, err = os.Open("./testdata/test.mtree")
|
fh, err = os.Open(testPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXattr(t *testing.T) {
|
func TestXattr(t *testing.T) {
|
||||||
fh, err := ioutil.TempFile(".", "xattr.")
|
testDir, present := os.LookupEnv("MTREE_TESTDIR")
|
||||||
|
if present == false {
|
||||||
|
testDir = "."
|
||||||
|
}
|
||||||
|
fh, err := ioutil.TempFile(testDir, "xattr.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue