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.
This commit is contained in:
parent
f48b731e76
commit
06f1ea951b
|
@ -356,34 +356,41 @@ func TestRename(t *testing.T, plainDir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyExistence checks in 3 ways that "path" exists:
|
// 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 {
|
func VerifyExistence(path string) bool {
|
||||||
// Check that file can be stated
|
// Check that file can be stated
|
||||||
|
stat := true
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//t.Log(err)
|
//t.Log(err)
|
||||||
return false
|
stat = false
|
||||||
}
|
}
|
||||||
// Check that file can be opened
|
// Check that file can be opened
|
||||||
|
open := true
|
||||||
fd, err := os.Open(path)
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//t.Log(err)
|
//t.Log(err)
|
||||||
return false
|
open = false
|
||||||
}
|
}
|
||||||
fd.Close()
|
fd.Close()
|
||||||
// Check that file shows up in directory listing
|
// Check that file shows up in directory listing
|
||||||
|
readdir := false
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
name := filepath.Base(path)
|
name := filepath.Base(path)
|
||||||
fi, err := ioutil.ReadDir(dir)
|
fi, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
//t.Log(err)
|
for _, i := range fi {
|
||||||
return false
|
if i.Name() == name {
|
||||||
}
|
readdir = true
|
||||||
for _, i := range fi {
|
}
|
||||||
if i.Name() == name {
|
|
||||||
return 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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue