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) { ...@@ -74,27 +74,31 @@ func TestFopenKeepCache(t *testing.T) {
wd, pathfs, clean := setupCacheTest(t) wd, pathfs, clean := setupCacheTest(t)
defer clean() defer clean()
before := "before" // x{read,write}File reads/writes file@path and fail on error
after := "after" xreadFile := func(path string) string {
if err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(before), 0644); err != nil { data, err := ioutil.ReadFile(path)
t.Fatalf("WriteFile failed: %v", err) if err != nil {
t.Fatal(err)
}
return string(data)
} }
xwriteFile := func(path, data string) {
c, err := ioutil.ReadFile(wd + "/mnt/file.txt") if err := ioutil.WriteFile(path, []byte(data), 0644); err != nil {
if err != nil { t.Fatal(err)
t.Fatalf("ReadFile: %v", err) }
} else if string(c) != before {
t.Fatalf("ReadFile: got %q, want %q", c, before)
} }
if err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(after), 0644); err != nil { before := "before"
t.Fatalf("WriteFile: %v", err) 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") xwriteFile(wd+"/orig/file.txt", after)
if err != nil { c = xreadFile(wd + "/mnt/file.txt")
t.Fatalf("ReadFile: %v", err) if c != before {
} else if string(c) != before {
t.Fatalf("ReadFile: got %q, want cached %q", c, before) t.Fatalf("ReadFile: got %q, want cached %q", c, before)
} }
...@@ -107,10 +111,8 @@ func TestFopenKeepCache(t *testing.T) { ...@@ -107,10 +111,8 @@ func TestFopenKeepCache(t *testing.T) {
t.Errorf("EntryNotify: %v", code) t.Errorf("EntryNotify: %v", code)
} }
c, err = ioutil.ReadFile(wd + "/mnt/file.txt") c = xreadFile(wd + "/mnt/file.txt")
if err != nil { if c != after {
t.Fatalf("ReadFile: %v", err)
} else if string(c) != after {
t.Fatalf("ReadFile: got %q after notify, want %q", 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