summaryrefslogtreecommitdiff
path: root/tests/test_helpers
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-01-04 17:32:27 +0100
committerJakob Unterwurzacher2019-01-04 17:36:06 +0100
commita2f83acc303e7ba382c6cbd0e8d218832166fc4d (patch)
treed2bac66ec085d38175cb2eed900147195a97ec79 /tests/test_helpers
parentcdb57ca7e0b99ee8e5a844d5177d03d5857fab27 (diff)
tests: fix VerifyExistence() helper, it missed unstat()able files
VerifyExistence missed unstat()able files in the directory listing because ioutil.ReadDir() filtered them out. https://github.com/rfjakob/gocryptfs/issues/285
Diffstat (limited to 'tests/test_helpers')
-rw-r--r--tests/test_helpers/helpers.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index 90eebdf..e735cf4 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -272,29 +272,34 @@ func TestRename(t *testing.T, plainDir string) {
// stat, open, readdir. Returns true if the path exists, false otherwise.
// Panics if the result is inconsistent.
func VerifyExistence(path string) bool {
- // Check that file can be stated
+ // Check if file can be stat()ed
stat := true
- _, err := os.Stat(path)
+ fi, err := os.Stat(path)
if err != nil {
- //t.Log(err)
stat = false
}
- // Check that file can be opened
+ // Check if file can be opened
open := true
fd, err := os.Open(path)
if err != nil {
- //t.Log(err)
open = false
}
fd.Close()
- // Check that file shows up in directory listing
+ // Check if file shows up in directory listing
readdir := false
dir := filepath.Dir(path)
name := filepath.Base(path)
- fi, err := ioutil.ReadDir(dir)
- if err == nil {
- for _, i := range fi {
- if i.Name() == name {
+ d, err := os.Open(dir)
+ if err != nil && open == true {
+ log.Panicf("we can open the file but not the parent dir!? err=%v", err)
+ } else if err == nil {
+ defer d.Close()
+ listing, err := d.Readdirnames(0)
+ if stat && fi.IsDir() && err != nil {
+ log.Panicf("It's a directory, but readdirnames failed: %v", err)
+ }
+ for _, entry := range listing {
+ if entry == name {
readdir = true
}
}
@@ -303,7 +308,7 @@ func VerifyExistence(path string) bool {
if stat == open && open == readdir {
return stat
}
- log.Panicf("inconsistent result: stat=%v open=%v readdir=%v", stat, open, readdir)
+ log.Panicf("inconsistent result on %q: stat=%v open=%v readdir=%v, path=%q", name, stat, open, readdir, path)
return false
}