Commit 0d80af72 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Han-Wen Nienhuys

fuse/test: TestFopenKeepCache: denoise

We have many calls to ioutil.WriteFile and ioutil.ReadFile + checking
for error. Move those calls into utility functions which call t.Fatal if
they see any error. No need to use additional error prefix as both
ioutil.WriteFile and ReadFile produce os.PathError which always has
opertion and path on which it was performed.
parent 39953190
......@@ -74,27 +74,31 @@ func TestFopenKeepCache(t *testing.T) {
wd, pathfs, clean := setupCacheTest(t)
defer clean()
before := "before"
after := "after"
if err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(before), 0644); err != nil {
t.Fatalf("WriteFile failed: %v", err)
// x{read,write}File reads/writes file@path and fail on error
xreadFile := func(path string) string {
data, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return string(data)
}
c, err := ioutil.ReadFile(wd + "/mnt/file.txt")
if err != nil {
t.Fatalf("ReadFile: %v", err)
} else if string(c) != before {
t.Fatalf("ReadFile: got %q, want %q", c, before)
xwriteFile := func(path, data string) {
if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil {
t.Fatal(err)
}
}
if err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(after), 0644); err != nil {
t.Fatalf("WriteFile: %v", err)
before := "before"
after := "after"
xwriteFile(wd+"/orig/file.txt", before)
c := xreadFile(wd + "/mnt/file.txt")
if c != before {
t.Fatalf("ReadFile: got %q, want %q", c, before)
}
c, err = ioutil.ReadFile(wd + "/mnt/file.txt")
if err != nil {
t.Fatalf("ReadFile: %v", err)
} else if string(c) != before {
xwriteFile(wd+"/orig/file.txt", after)
c = xreadFile(wd + "/mnt/file.txt")
if c != before {
t.Fatalf("ReadFile: got %q, want cached %q", c, before)
}
......@@ -107,10 +111,8 @@ func TestFopenKeepCache(t *testing.T) {
t.Errorf("EntryNotify: %v", code)
}
c, err = ioutil.ReadFile(wd + "/mnt/file.txt")
if err != nil {
t.Fatalf("ReadFile: %v", err)
} else if string(c) != after {
c = xreadFile(wd + "/mnt/file.txt")
if c != after {
t.Fatalf("ReadFile: got %q after notify, want %q", c, after)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment