From 9d44c3003b295701ee0989a37d51d15271f7a6a1 Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Fri, 11 Dec 2015 11:02:03 +0100 Subject: [PATCH] add a test for twice calling Create on the same path --- afero_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/afero_test.go b/afero_test.go index 528689a..6c9c64b 100644 --- a/afero_test.go +++ b/afero_test.go @@ -120,6 +120,52 @@ func TestOpenFile(t *testing.T) { } } +func TestCreate(t *testing.T) { + defer removeAllTestFiles(t) + for _, fs := range Fss { + tmp := testDir(fs) + path := filepath.Join(tmp, testName) + + f, err := fs.Create(path) + if err != nil { + t.Error(fs.Name(), "Create failed:", err) + f.Close() + continue + } + io.WriteString(f, "initial") + f.Close() + + f, err = fs.Create(path) + if err != nil { + t.Error(fs.Name(), "Create failed:", err) + f.Close() + continue + } + secondContent := "second create" + io.WriteString(f, secondContent) + f.Close() + + f, err = fs.Open(path) + if err != nil { + t.Error(fs.Name(), "Open failed:", err) + f.Close() + continue + } + buf, err := ReadAll(f) + if err != nil { + t.Error(fs.Name(), "ReadAll failed:", err) + f.Close() + continue + } + if string(buf) != secondContent { + t.Error(fs.Name(), "Content should be", "\""+secondContent+"\" but is \""+string(buf)+"\"") + f.Close() + continue + } + f.Close() + } +} + func TestMemFileRead(t *testing.T) { f := tmpFile(new(MemMapFs)) // f := MemFileCreate("testfile")