From 06f1ea951b03b4a0e8f6090c6657b8e0238da271 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 11 Aug 2018 22:37:22 +0200 Subject: 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. --- tests/test_helpers/helpers.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'tests/test_helpers') 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 } -- cgit v1.2.3