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
51
52
53
54
55
56
57
58
59
60
|
package fsck
import (
"os"
"os/exec"
"strings"
"testing"
"github.com/rfjakob/gocryptfs/internal/exitcodes"
"github.com/rfjakob/gocryptfs/tests/test_helpers"
)
func TestBrokenFsV14(t *testing.T) {
cmd := exec.Command(test_helpers.GocryptfsBinary, "-fsck", "-extpass", "echo test", "broken_fs_v1.4")
outBin, err := cmd.CombinedOutput()
out := string(outBin)
t.Log(out)
code := test_helpers.ExtractCmdExitCode(err)
if code != exitcodes.FsckErrors {
t.Errorf("wrong exit code, have=%d want=%d", code, exitcodes.FsckErrors)
}
}
func TestExampleFses(t *testing.T) {
dirfd, err := os.Open("../example_filesystems")
if err != nil {
t.Fatal(err)
}
var fsNames []string
entries, err := dirfd.Readdir(0)
if err != nil {
t.Fatal(err)
}
for _, e := range entries {
if !e.IsDir() {
continue
}
if strings.Contains(e.Name(), "reverse") {
continue
}
if e.Name() == "content" {
continue
}
fsNames = append(fsNames, e.Name())
}
for _, n := range fsNames {
path := "../example_filesystems/" + n
cmd := exec.Command(test_helpers.GocryptfsBinary, "-fsck", "-extpass", "echo test", path)
outBin, err := cmd.CombinedOutput()
out := string(outBin)
code := test_helpers.ExtractCmdExitCode(err)
if code == exitcodes.DeprecatedFS {
continue
}
if code != 0 {
t.Log(out)
t.Errorf("fsck returned code %d but fs should be clean", code)
}
}
}
|