2016-06-26 18:34:30 +02:00
|
|
|
package example_filesystems
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
|
|
|
)
|
|
|
|
|
|
|
|
// checkExampleFS - verify that "dir" contains the expected test files
|
|
|
|
func checkExampleFS(t *testing.T, dir string, rw bool) {
|
|
|
|
// Read regular file
|
|
|
|
statusFile := filepath.Join(dir, "status.txt")
|
|
|
|
contentBytes, err := ioutil.ReadFile(statusFile)
|
|
|
|
if err != nil {
|
2016-11-26 15:17:15 +01:00
|
|
|
t.Error(err)
|
|
|
|
return
|
2016-06-26 18:34:30 +02:00
|
|
|
}
|
|
|
|
content := string(contentBytes)
|
|
|
|
if content != statusTxtContent {
|
|
|
|
t.Errorf("Unexpected content: %s\n", content)
|
|
|
|
}
|
|
|
|
// Read relative symlink
|
|
|
|
symlink := filepath.Join(dir, "rel")
|
|
|
|
target, err := os.Readlink(symlink)
|
|
|
|
if err != nil {
|
2016-11-26 15:17:15 +01:00
|
|
|
t.Error(err)
|
|
|
|
return
|
2016-06-26 18:34:30 +02:00
|
|
|
}
|
|
|
|
if target != "status.txt" {
|
|
|
|
t.Errorf("Unexpected link target: %s\n", target)
|
|
|
|
}
|
|
|
|
// Read absolute symlink
|
|
|
|
symlink = filepath.Join(dir, "abs")
|
|
|
|
target, err = os.Readlink(symlink)
|
|
|
|
if err != nil {
|
2016-11-26 15:17:15 +01:00
|
|
|
t.Error(err)
|
|
|
|
return
|
2016-06-26 18:34:30 +02:00
|
|
|
}
|
|
|
|
if target != "/a/b/c/d" {
|
|
|
|
t.Errorf("Unexpected link target: %s\n", target)
|
|
|
|
}
|
|
|
|
if rw {
|
|
|
|
// Test directory operations
|
|
|
|
test_helpers.TestRename(t, dir)
|
|
|
|
test_helpers.TestMkdirRmdir(t, dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkExampleFSLongnames - verify that "dir" contains the expected test files
|
2016-10-08 21:45:11 +02:00
|
|
|
// plus the long file name test file.
|
|
|
|
// Also tests simple directory operations.
|
2016-06-26 18:34:30 +02:00
|
|
|
func checkExampleFSLongnames(t *testing.T, dir string) {
|
2016-10-08 21:45:11 +02:00
|
|
|
checkExampleFSrw(t, dir, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkExampleFSrw is like checkExampleFSLongnames but gives the caller the
|
|
|
|
// choice if he wants to run tests that write to the FS.
|
|
|
|
func checkExampleFSrw(t *testing.T, dir string, rw bool) {
|
2016-06-26 18:34:30 +02:00
|
|
|
// regular tests
|
2016-10-08 21:45:11 +02:00
|
|
|
checkExampleFS(t, dir, rw)
|
2016-06-26 18:34:30 +02:00
|
|
|
// long name test file
|
|
|
|
longname := "longname_255_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxx"
|
|
|
|
contentBytes, err := ioutil.ReadFile(filepath.Join(dir, longname))
|
|
|
|
if err != nil {
|
2017-03-05 13:39:25 +01:00
|
|
|
t.Error(err)
|
|
|
|
return
|
2016-06-26 18:34:30 +02:00
|
|
|
}
|
|
|
|
content := string(contentBytes)
|
|
|
|
if content != statusTxtContent {
|
|
|
|
t.Errorf("longname_255: unexpected content: %s\n", content)
|
|
|
|
}
|
|
|
|
}
|