mirror of https://github.com/spf13/afero.git
CacheOnReadFS: erroneous NotExists error
This commit is contained in:
parent
ee1bd8ee15
commit
655d0bd1f1
|
@ -1,6 +1,7 @@
|
|||
package afero
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -366,3 +367,38 @@ func TestUnionCacheExpire(t *testing.T) {
|
|||
t.Errorf("cache time failed: <%s>", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheOnReadFs_Open_NotInLayer(t *testing.T) {
|
||||
base := NewMemMapFs()
|
||||
layer := NewMemMapFs()
|
||||
fs := NewCacheOnReadFs(base, layer, 0)
|
||||
|
||||
fh, err := base.Create("/file.txt")
|
||||
if err != nil {
|
||||
t.Fatal("unable to create file: ", err)
|
||||
}
|
||||
|
||||
txt := []byte("This is a test")
|
||||
fh.Write(txt)
|
||||
fh.Close()
|
||||
|
||||
fh, err = fs.Open("/file.txt")
|
||||
if err != nil {
|
||||
t.Fatal("could not open file: ", err)
|
||||
}
|
||||
|
||||
b, err := ReadAll(fh)
|
||||
fh.Close()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("could not read file: ", err)
|
||||
} else if !bytes.Equal(txt, b) {
|
||||
t.Fatalf("wanted file text %q, got %q", txt, b)
|
||||
}
|
||||
|
||||
fh, err = layer.Open("/file.txt")
|
||||
if err != nil {
|
||||
t.Fatal("could not open file from layer: ", err)
|
||||
}
|
||||
fh.Close()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue