|
@@ -206,6 +206,64 @@ func TestMountChanges(t *testing.T) {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestMountApply(t *testing.T) {
|
|
|
|
+ // TODO Windows: Figure out why this is failing
|
|
|
|
+ if runtime.GOOS == "windows" {
|
|
|
|
+ t.Skip("Failing on Windows")
|
|
|
|
+ }
|
|
|
|
+ ls, _, cleanup := newTestStore(t)
|
|
|
|
+ defer cleanup()
|
|
|
|
+
|
|
|
|
+ basefile := newTestFile("testfile.txt", []byte("base data!"), 0644)
|
|
|
|
+ newfile := newTestFile("newfile.txt", []byte("new data!"), 0755)
|
|
|
|
+
|
|
|
|
+ li := initWithFiles(basefile)
|
|
|
|
+ layer, err := createLayer(ls, "", li)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ di := initWithFiles(newfile)
|
|
|
|
+ diffLayer, err := createLayer(ls, "", di)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ m, err := ls.CreateRWLayer("fun-mount", layer.ChainID(), nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r, err := diffLayer.TarStream()
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if _, err := m.ApplyDiff(r); err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pathFS, err := m.Mount("")
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ f, err := pathFS.Open(pathFS.Join(pathFS.Path(), "newfile.txt"))
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ defer f.Close()
|
|
|
|
+
|
|
|
|
+ b, err := ioutil.ReadAll(f)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if expected := "new data!"; string(b) != expected {
|
|
|
|
+ t.Fatalf("Unexpected test file contents %q, expected %q", string(b), expected)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func assertChange(t *testing.T, actual, expected archive.Change) {
|
|
func assertChange(t *testing.T, actual, expected archive.Change) {
|
|
if actual.Path != expected.Path {
|
|
if actual.Path != expected.Path {
|
|
t.Fatalf("Unexpected change path %s, expected %s", actual.Path, expected.Path)
|
|
t.Fatalf("Unexpected change path %s, expected %s", actual.Path, expected.Path)
|