forked from spf13/afero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyOnWriteFs_test.go
62 lines (50 loc) · 1.34 KB
/
copyOnWriteFs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package afero
import (
"os"
"path/filepath"
"testing"
)
func TestCopyOnWrite(t *testing.T) {
osFs := NewOsFs()
writeDir, err := TempDir(osFs, "", "copy-on-write-test")
if err != nil {
t.Fatal("error creating tempDir", err)
}
defer osFs.RemoveAll(writeDir)
compositeFs := NewCopyOnWriteFs(NewReadOnlyFs(NewOsFs()), osFs)
dir := filepath.Join(writeDir, "some/path")
err = compositeFs.MkdirAll(dir, 0o744)
if err != nil {
t.Fatal(err)
}
_, err = compositeFs.Create(filepath.Join(dir, "newfile"))
if err != nil {
t.Fatal(err)
}
// https://github.com/spf13/afero/issues/189
// We want the composite file system to behave like the OS file system
// on Mkdir and MkdirAll
for _, fs := range []Fs{osFs, compositeFs} {
err = fs.Mkdir(dir, 0o744)
if err == nil || !os.IsExist(err) {
t.Errorf("Mkdir: Got %q for %T", err, fs)
}
// MkdirAll does not return an error when the directory already exists
err = fs.MkdirAll(dir, 0o744)
if err != nil {
t.Errorf("MkdirAll: Got %q for %T", err, fs)
}
}
}
func TestCopyOnWriteFileInMemMapBase(t *testing.T) {
base := &MemMapFs{}
layer := &MemMapFs{}
if err := WriteFile(base, "base.txt", []byte("base"), 0o755); err != nil {
t.Fatalf("Failed to write file: %s", err)
}
ufs := NewCopyOnWriteFs(base, layer)
_, err := ufs.Stat("base.txt")
if err != nil {
t.Fatal(err)
}
}