tests: test read-write directory operations on all example filesystems
This commit is contained in:
parent
29336ba614
commit
61ee2271c4
@ -13,8 +13,8 @@ const statusTxtContent = "It works!\n"
|
|||||||
|
|
||||||
// checkStatusTxt - read file "filename" and verify that it contains
|
// checkStatusTxt - read file "filename" and verify that it contains
|
||||||
// "It works!\n"
|
// "It works!\n"
|
||||||
func checkExampleContent(t *testing.T, dir string) {
|
func checkExampleFS(t *testing.T, dir string) {
|
||||||
// Check regular file
|
// Read regular file
|
||||||
statusFile := filepath.Join(dir, "status.txt")
|
statusFile := filepath.Join(dir, "status.txt")
|
||||||
contentBytes, err := ioutil.ReadFile(statusFile)
|
contentBytes, err := ioutil.ReadFile(statusFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -24,7 +24,7 @@ func checkExampleContent(t *testing.T, dir string) {
|
|||||||
if content != statusTxtContent {
|
if content != statusTxtContent {
|
||||||
t.Errorf("Unexpected content: %s\n", content)
|
t.Errorf("Unexpected content: %s\n", content)
|
||||||
}
|
}
|
||||||
// Check relative symlink
|
// Read relative symlink
|
||||||
symlink := filepath.Join(dir, "rel")
|
symlink := filepath.Join(dir, "rel")
|
||||||
target, err := os.Readlink(symlink)
|
target, err := os.Readlink(symlink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,7 +33,7 @@ func checkExampleContent(t *testing.T, dir string) {
|
|||||||
if target != "status.txt" {
|
if target != "status.txt" {
|
||||||
t.Errorf("Unexpected link target: %s\n", target)
|
t.Errorf("Unexpected link target: %s\n", target)
|
||||||
}
|
}
|
||||||
// Check absolute symlink
|
// Read absolute symlink
|
||||||
symlink = filepath.Join(dir, "abs")
|
symlink = filepath.Join(dir, "abs")
|
||||||
target, err = os.Readlink(symlink)
|
target, err = os.Readlink(symlink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,11 +42,14 @@ func checkExampleContent(t *testing.T, dir string) {
|
|||||||
if target != "/a/b/c/d" {
|
if target != "/a/b/c/d" {
|
||||||
t.Errorf("Unexpected link target: %s\n", target)
|
t.Errorf("Unexpected link target: %s\n", target)
|
||||||
}
|
}
|
||||||
|
// Test directory operations
|
||||||
|
testRename(t, dir)
|
||||||
|
testMkdirRmdir(t, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test example_filesystems/v0.4
|
// Test example_filesystems/v0.4
|
||||||
// with password mount and -masterkey mount
|
// with password mount and -masterkey mount
|
||||||
func TestExampleFsV04(t *testing.T) {
|
func TestExampleFSv04(t *testing.T) {
|
||||||
pDir := tmpDir + "TestExampleFsV04/"
|
pDir := tmpDir + "TestExampleFsV04/"
|
||||||
cDir := "example_filesystems/v0.4"
|
cDir := "example_filesystems/v0.4"
|
||||||
err := os.Mkdir(pDir, 0777)
|
err := os.Mkdir(pDir, 0777)
|
||||||
@ -54,11 +57,11 @@ func TestExampleFsV04(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mount(cDir, pDir, "-extpass", "echo test")
|
mount(cDir, pDir, "-extpass", "echo test")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
mount(cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
|
mount(cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
|
||||||
"bb57044c-e205b71f-65f4fdca-7cabd4b3", "-diriv=false", "-emenames=false")
|
"bb57044c-e205b71f-65f4fdca-7cabd4b3", "-diriv=false", "-emenames=false")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
err = os.Remove(pDir)
|
err = os.Remove(pDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,7 +71,7 @@ func TestExampleFsV04(t *testing.T) {
|
|||||||
|
|
||||||
// Test example_filesystems/v0.5
|
// Test example_filesystems/v0.5
|
||||||
// with password mount and -masterkey mount
|
// with password mount and -masterkey mount
|
||||||
func TestExampleFsV05(t *testing.T) {
|
func TestExampleFSv05(t *testing.T) {
|
||||||
pDir := tmpDir + "TestExampleFsV05/"
|
pDir := tmpDir + "TestExampleFsV05/"
|
||||||
cDir := "example_filesystems/v0.5"
|
cDir := "example_filesystems/v0.5"
|
||||||
err := os.Mkdir(pDir, 0777)
|
err := os.Mkdir(pDir, 0777)
|
||||||
@ -76,11 +79,11 @@ func TestExampleFsV05(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mount(cDir, pDir, "-extpass", "echo test")
|
mount(cDir, pDir, "-extpass", "echo test")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
mount(cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
|
mount(cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
|
||||||
"1549ccdb-2d08d1f0-b1b26965-1b61f896", "-emenames=false")
|
"1549ccdb-2d08d1f0-b1b26965-1b61f896", "-emenames=false")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
err = os.Remove(pDir)
|
err = os.Remove(pDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,7 +93,7 @@ func TestExampleFsV05(t *testing.T) {
|
|||||||
|
|
||||||
// Test example_filesystems/v0.6
|
// Test example_filesystems/v0.6
|
||||||
// with password mount and -masterkey mount
|
// with password mount and -masterkey mount
|
||||||
func TestExampleFsV06(t *testing.T) {
|
func TestExampleFSv06(t *testing.T) {
|
||||||
pDir := tmpDir + "TestExampleFsV06/"
|
pDir := tmpDir + "TestExampleFsV06/"
|
||||||
cDir := "example_filesystems/v0.6"
|
cDir := "example_filesystems/v0.6"
|
||||||
err := os.Mkdir(pDir, 0777)
|
err := os.Mkdir(pDir, 0777)
|
||||||
@ -98,11 +101,11 @@ func TestExampleFsV06(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mount(cDir, pDir, "-extpass", "echo test")
|
mount(cDir, pDir, "-extpass", "echo test")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
mount(cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
|
mount(cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
|
||||||
"0e8dee83-fdc056a4-937c37dd-9df5c520")
|
"0e8dee83-fdc056a4-937c37dd-9df5c520")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
err = os.Remove(pDir)
|
err = os.Remove(pDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -112,7 +115,7 @@ func TestExampleFsV06(t *testing.T) {
|
|||||||
|
|
||||||
// Test example_filesystems/v0.6
|
// Test example_filesystems/v0.6
|
||||||
// with password mount and -masterkey mount
|
// with password mount and -masterkey mount
|
||||||
func TestExampleFsV06PlaintextNames(t *testing.T) {
|
func TestExampleFSv06PlaintextNames(t *testing.T) {
|
||||||
pDir := tmpDir + "TestExampleFsV06PlaintextNames/"
|
pDir := tmpDir + "TestExampleFsV06PlaintextNames/"
|
||||||
cDir := "example_filesystems/v0.6-plaintextnames"
|
cDir := "example_filesystems/v0.6-plaintextnames"
|
||||||
err := os.Mkdir(pDir, 0777)
|
err := os.Mkdir(pDir, 0777)
|
||||||
@ -120,11 +123,11 @@ func TestExampleFsV06PlaintextNames(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mount(cDir, pDir, "-extpass", "echo test")
|
mount(cDir, pDir, "-extpass", "echo test")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
mount(cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
|
mount(cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
|
||||||
"303147f9-0ca8aea2-966341a7-52ea8ae9", "-plaintextnames")
|
"303147f9-0ca8aea2-966341a7-52ea8ae9", "-plaintextnames")
|
||||||
checkExampleContent(t, pDir)
|
checkExampleFS(t, pDir)
|
||||||
unmount(pDir)
|
unmount(pDir)
|
||||||
err = os.Remove(pDir)
|
err = os.Remove(pDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package integration_tests
|
package integration_tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"syscall"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -51,6 +52,7 @@ func resetTmpDir() {
|
|||||||
func mount(c string, p string, extraArgs ...string) {
|
func mount(c string, p string, extraArgs ...string) {
|
||||||
var args []string
|
var args []string
|
||||||
args = append(args, extraArgs...)
|
args = append(args, extraArgs...)
|
||||||
|
args = append(args, "-q")
|
||||||
//args = append(args, "--fusedebug")
|
//args = append(args, "--fusedebug")
|
||||||
args = append(args, c)
|
args = append(args, c)
|
||||||
args = append(args, p)
|
args = append(args, p)
|
||||||
@ -113,3 +115,31 @@ func verifySize(t *testing.T, path string, want int) {
|
|||||||
t.Errorf("wrong stat file size, got=%d want=%d", fi.Size(), want)
|
t.Errorf("wrong stat file size, got=%d want=%d", fi.Size(), want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create and delete a directory
|
||||||
|
func testMkdirRmdir(t *testing.T, plainDir string) {
|
||||||
|
dir := plainDir + "dir1"
|
||||||
|
err := os.Mkdir(dir, 0777)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
err = syscall.Rmdir(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and rename a file
|
||||||
|
func testRename(t *testing.T, plainDir string) {
|
||||||
|
file1 := plainDir+"rename1"
|
||||||
|
file2 := plainDir+"rename2"
|
||||||
|
err := ioutil.WriteFile(file1, []byte("content"), 0777)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
err = syscall.Rename(file1, file2)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
syscall.Unlink(file2)
|
||||||
|
}
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -314,25 +313,10 @@ func TestFilenameEncryption(t *testing.T) {
|
|||||||
|
|
||||||
// Test Mkdir and Rmdir
|
// Test Mkdir and Rmdir
|
||||||
func TestMkdirRmdir(t *testing.T) {
|
func TestMkdirRmdir(t *testing.T) {
|
||||||
dir := defaultPlainDir + "dir1"
|
testMkdirRmdir(t, defaultPlainDir)
|
||||||
err := os.Mkdir(dir, 0777)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
err = syscall.Rmdir(dir)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Rename
|
// Test Rename
|
||||||
func TestRename(t *testing.T) {
|
func TestRename(t *testing.T) {
|
||||||
err := ioutil.WriteFile(defaultPlainDir+"rename1", []byte("content"), 0777)
|
testRename(t, defaultPlainDir)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
err = syscall.Rename(defaultPlainDir+"rename1", defaultPlainDir+"rename2")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user