tests: test read-write directory operations on all example filesystems

This commit is contained in:
Jakob Unterwurzacher 2015-12-10 20:02:18 +01:00
parent 29336ba614
commit 61ee2271c4
3 changed files with 51 additions and 34 deletions

View File

@ -13,8 +13,8 @@ const statusTxtContent = "It works!\n"
// checkStatusTxt - read file "filename" and verify that it contains
// "It works!\n"
func checkExampleContent(t *testing.T, dir string) {
// Check regular file
func checkExampleFS(t *testing.T, dir string) {
// Read regular file
statusFile := filepath.Join(dir, "status.txt")
contentBytes, err := ioutil.ReadFile(statusFile)
if err != nil {
@ -24,7 +24,7 @@ func checkExampleContent(t *testing.T, dir string) {
if content != statusTxtContent {
t.Errorf("Unexpected content: %s\n", content)
}
// Check relative symlink
// Read relative symlink
symlink := filepath.Join(dir, "rel")
target, err := os.Readlink(symlink)
if err != nil {
@ -33,7 +33,7 @@ func checkExampleContent(t *testing.T, dir string) {
if target != "status.txt" {
t.Errorf("Unexpected link target: %s\n", target)
}
// Check absolute symlink
// Read absolute symlink
symlink = filepath.Join(dir, "abs")
target, err = os.Readlink(symlink)
if err != nil {
@ -42,11 +42,14 @@ func checkExampleContent(t *testing.T, dir string) {
if target != "/a/b/c/d" {
t.Errorf("Unexpected link target: %s\n", target)
}
// Test directory operations
testRename(t, dir)
testMkdirRmdir(t, dir)
}
// Test example_filesystems/v0.4
// with password mount and -masterkey mount
func TestExampleFsV04(t *testing.T) {
func TestExampleFSv04(t *testing.T) {
pDir := tmpDir + "TestExampleFsV04/"
cDir := "example_filesystems/v0.4"
err := os.Mkdir(pDir, 0777)
@ -54,11 +57,11 @@ func TestExampleFsV04(t *testing.T) {
t.Fatal(err)
}
mount(cDir, pDir, "-extpass", "echo test")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
mount(cDir, pDir, "-masterkey", "74676e34-0b47c145-00dac61a-17a92316-"+
"bb57044c-e205b71f-65f4fdca-7cabd4b3", "-diriv=false", "-emenames=false")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
err = os.Remove(pDir)
if err != nil {
@ -68,7 +71,7 @@ func TestExampleFsV04(t *testing.T) {
// Test example_filesystems/v0.5
// with password mount and -masterkey mount
func TestExampleFsV05(t *testing.T) {
func TestExampleFSv05(t *testing.T) {
pDir := tmpDir + "TestExampleFsV05/"
cDir := "example_filesystems/v0.5"
err := os.Mkdir(pDir, 0777)
@ -76,11 +79,11 @@ func TestExampleFsV05(t *testing.T) {
t.Fatal(err)
}
mount(cDir, pDir, "-extpass", "echo test")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
mount(cDir, pDir, "-masterkey", "199eae55-36bff4af-83b9a3a2-4fa16f65-"+
"1549ccdb-2d08d1f0-b1b26965-1b61f896", "-emenames=false")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
err = os.Remove(pDir)
if err != nil {
@ -90,7 +93,7 @@ func TestExampleFsV05(t *testing.T) {
// Test example_filesystems/v0.6
// with password mount and -masterkey mount
func TestExampleFsV06(t *testing.T) {
func TestExampleFSv06(t *testing.T) {
pDir := tmpDir + "TestExampleFsV06/"
cDir := "example_filesystems/v0.6"
err := os.Mkdir(pDir, 0777)
@ -98,11 +101,11 @@ func TestExampleFsV06(t *testing.T) {
t.Fatal(err)
}
mount(cDir, pDir, "-extpass", "echo test")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
mount(cDir, pDir, "-masterkey", "7bc8deb0-5fc894ef-a093da43-61561a81-"+
"0e8dee83-fdc056a4-937c37dd-9df5c520")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
err = os.Remove(pDir)
if err != nil {
@ -112,7 +115,7 @@ func TestExampleFsV06(t *testing.T) {
// Test example_filesystems/v0.6
// with password mount and -masterkey mount
func TestExampleFsV06PlaintextNames(t *testing.T) {
func TestExampleFSv06PlaintextNames(t *testing.T) {
pDir := tmpDir + "TestExampleFsV06PlaintextNames/"
cDir := "example_filesystems/v0.6-plaintextnames"
err := os.Mkdir(pDir, 0777)
@ -120,11 +123,11 @@ func TestExampleFsV06PlaintextNames(t *testing.T) {
t.Fatal(err)
}
mount(cDir, pDir, "-extpass", "echo test")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
mount(cDir, pDir, "-masterkey", "f4690202-595e4593-64c4f7e0-4dddd7d1-"+
"303147f9-0ca8aea2-966341a7-52ea8ae9", "-plaintextnames")
checkExampleContent(t, pDir)
checkExampleFS(t, pDir)
unmount(pDir)
err = os.Remove(pDir)
if err != nil {

View File

@ -1,6 +1,7 @@
package integration_tests
import (
"syscall"
"crypto/md5"
"encoding/hex"
"fmt"
@ -51,6 +52,7 @@ func resetTmpDir() {
func mount(c string, p string, extraArgs ...string) {
var args []string
args = append(args, extraArgs...)
args = append(args, "-q")
//args = append(args, "--fusedebug")
args = append(args, c)
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)
}
}
// 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)
}

View File

@ -12,7 +12,6 @@ import (
"os"
"runtime"
"sync"
"syscall"
"testing"
)
@ -314,25 +313,10 @@ func TestFilenameEncryption(t *testing.T) {
// Test Mkdir and Rmdir
func TestMkdirRmdir(t *testing.T) {
dir := defaultPlainDir + "dir1"
err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)
}
err = syscall.Rmdir(dir)
if err != nil {
t.Fatal(err)
}
testMkdirRmdir(t, defaultPlainDir)
}
// Test Rename
func TestRename(t *testing.T) {
err := ioutil.WriteFile(defaultPlainDir+"rename1", []byte("content"), 0777)
if err != nil {
t.Fatal(err)
}
err = syscall.Rename(defaultPlainDir+"rename1", defaultPlainDir+"rename2")
if err != nil {
t.Fatal(err)
}
testRename(t, defaultPlainDir)
}