forked from mirror/afero
add a test for twice calling Create on the same path
This commit is contained in:
parent
12f79b29b2
commit
9d44c3003b
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue