summaryrefslogtreecommitdiff
path: root/tests/matrix/dir_test.go
blob: 2f9f1b0c3437ab877043846f8db8082d78aff06a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package matrix

import (
	"fmt"
	"os"
	"syscall"
	"testing"

	"github.com/rfjakob/gocryptfs/tests/test_helpers"
)

// Test Mkdir and Rmdir
func TestMkdirRmdir(t *testing.T) {
	test_helpers.TestMkdirRmdir(t, test_helpers.DefaultPlainDir)
}

// Overwrite an empty directory with another directory
func TestDirOverwrite(t *testing.T) {
	dir1 := test_helpers.DefaultPlainDir + "/DirOverwrite1"
	dir2 := test_helpers.DefaultPlainDir + "/DirOverwrite2"
	err := os.Mkdir(dir1, 0777)
	if err != nil {
		t.Fatal(err)
	}
	err = os.Mkdir(dir2, 0777)
	if err != nil {
		t.Fatal(err)
	}
	err = syscall.Rename(dir1, dir2)
	if err != nil {
		t.Fatal(err)
	}
}

// Test that we can create and remove a directory regardless of the permission it has
// https://github.com/rfjakob/gocryptfs/issues/354
func TestRmdirPerms(t *testing.T) {
	for _, perm := range []uint32{0000, 0100, 0200, 0300, 0400, 0500, 0600, 0700} {
		dir := fmt.Sprintf("TestRmdir%#o", perm)
		path := test_helpers.DefaultPlainDir + "/" + dir
		err := syscall.Mkdir(path, perm)
		if err != nil {
			t.Fatalf("Mkdir %q: %v", dir, err)
		}
		err = syscall.Rmdir(path)
		if err != nil {
			t.Fatalf("Rmdir %q: %v", dir, err)
		}
	}
}