snapshot/overlay: implement view
Allow creating actives without an upper directory for capturing changes. Actives without the upper directory will always be mounted read only. Read only actives must have a parent. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
5bdfeead5e
commit
ca56448263
2 changed files with 83 additions and 13 deletions
|
@ -2,6 +2,7 @@ package overlay
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -196,3 +197,49 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlayView(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := "/tmp/test"
|
||||
mounts, err := o.Prepare(ctx, key, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := mounts[0]
|
||||
if err := ioutil.WriteFile(filepath.Join(m.Source, "foo"), []byte("hi"), 0660); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := o.Commit(ctx, "base", key); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mounts, err = o.View(ctx, "/tmp/test2", "base")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(mounts) != 1 {
|
||||
t.Fatalf("should only have 1 mount but received %d", len(mounts))
|
||||
}
|
||||
m = mounts[0]
|
||||
if m.Type != "overlay" {
|
||||
t.Errorf("mount type should be overlay but received %q", m.Type)
|
||||
}
|
||||
if m.Source != "overlay" {
|
||||
t.Errorf("mount source should be overlay but received %q", m.Source)
|
||||
}
|
||||
if len(m.Options) != 1 {
|
||||
t.Errorf("expected 1 mount option but got %d", len(m.Options))
|
||||
}
|
||||
expected := fmt.Sprintf("lowerdir=%s", filepath.Join(root, "committed", hash("base"), "fs"))
|
||||
if m.Options[0] != expected {
|
||||
t.Errorf("expected option %q but received %q", expected, m.Options[0])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue