summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-08-11 22:37:22 +0200
committerJakob Unterwurzacher2018-08-11 22:37:22 +0200
commit06f1ea951b03b4a0e8f6090c6657b8e0238da271 (patch)
treec3929aa9c17b87684893c8ecbe19ac5b459652d1 /tests
parentf48b731e76fb199352d3e80ea49d76865ee6e604 (diff)
tests: VerifyExistence: panic on inconsistent results
In the past we did not check whether all methods of checking the file return the same result. We should.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_helpers/helpers.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index ef748e2..479bf72 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -356,34 +356,41 @@ func TestRename(t *testing.T, plainDir string) {
}
// VerifyExistence checks in 3 ways that "path" exists:
-// stat, open, readdir
+// 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
+ stat := true
_, err := os.Stat(path)
if err != nil {
//t.Log(err)
- return false
+ stat = false
}
// Check that file can be opened
+ open := true
fd, err := os.Open(path)
if err != nil {
//t.Log(err)
- return false
+ open = false
}
fd.Close()
// Check that file shows up in directory listing
+ readdir := false
dir := filepath.Dir(path)
name := filepath.Base(path)
fi, err := ioutil.ReadDir(dir)
- if err != nil {
- //t.Log(err)
- return false
- }
- for _, i := range fi {
- if i.Name() == name {
- return true
+ if err == nil {
+ for _, i := range fi {
+ if i.Name() == name {
+ readdir = true
+ }
}
}
+ // If the result is consistent, return it.
+ if stat == open && open == readdir {
+ return stat
+ }
+ log.Panicf("inconsistent result: stat=%v open=%v readdir=%v", stat, open, readdir)
return false
}