aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-12-02 19:57:23 +0100
committerJakob Unterwurzacher2017-12-02 19:57:23 +0100
commit1d289736110f99e63a01449312888e5c3f241656 (patch)
treee68c87085fc8590042f2be0fda7b38eabe8db471 /internal/syscallcompat/main_test.go
parent77191c3485fd0a0b626aaf51382018a700057225 (diff)
syscallcompat: move test setup into its own file
The infrastructure will also be used by the upcoming OpenNofollow tests.
Diffstat (limited to 'internal/syscallcompat/main_test.go')
-rw-r--r--internal/syscallcompat/main_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/syscallcompat/main_test.go b/internal/syscallcompat/main_test.go
new file mode 100644
index 0000000..43db0e1
--- /dev/null
+++ b/internal/syscallcompat/main_test.go
@@ -0,0 +1,47 @@
+package syscallcompat
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "testing"
+)
+
+var tmpDir string
+var tmpDirFd int
+
+func TestMain(m *testing.M) {
+ origWd, err := os.Getwd()
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ parent := "/tmp/gocryptfs-test-parent"
+ err = os.MkdirAll(parent, 0700)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ tmpDir, err = ioutil.TempDir(parent, "syscallcompat")
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ dirf, err := os.Open(tmpDir)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ defer dirf.Close()
+ tmpDirFd = int(dirf.Fd())
+ // Run the tests
+ r := m.Run()
+ // Check that we are in the same directory again (the emulated syscalls
+ // use Fchdir a lot)
+ cwd, _ := os.Getwd()
+ if cwd != origWd {
+ fmt.Printf("working dir has changed from %q to %q", origWd, cwd)
+ os.Exit(1)
+ }
+ os.Exit(r)
+}