1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/graphdriver/btrfs/btrfs_test.go
Brian Goff f9befce2d3 Fix btrfs recursive btrfs subvol delete
Really fixing 2 things:

1. Panic when any error is detected while walking the btrfs graph dir on
removal due to no error check.
2. Nested subvolumes weren't actually being removed due to passing in
the wrong path

On point 2, for a path detected as a nested subvolume, we were calling
`subvolDelete("/path/to/subvol", "subvol")`, where the last part of the
path was duplicated due to a logic error, and as such actually causing
point #1 since `subvolDelete` joins the two arguemtns, and
`/path/to/subvol/subvol` (the joined version) doesn't exist.

Also adds a test for nested subvol delete.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-12-15 18:12:40 -05:00

63 lines
1.3 KiB
Go

// +build linux
package btrfs
import (
"os"
"path"
"testing"
"github.com/docker/docker/daemon/graphdriver/graphtest"
)
// This avoids creating a new driver for each test if all tests are run
// Make sure to put new tests between TestBtrfsSetup and TestBtrfsTeardown
func TestBtrfsSetup(t *testing.T) {
graphtest.GetDriver(t, "btrfs")
}
func TestBtrfsCreateEmpty(t *testing.T) {
graphtest.DriverTestCreateEmpty(t, "btrfs")
}
func TestBtrfsCreateBase(t *testing.T) {
graphtest.DriverTestCreateBase(t, "btrfs")
}
func TestBtrfsCreateSnap(t *testing.T) {
graphtest.DriverTestCreateSnap(t, "btrfs")
}
func TestBtrfsSubvolDelete(t *testing.T) {
d := graphtest.GetDriver(t, "btrfs")
if err := d.Create("test", "", ""); err != nil {
t.Fatal(err)
}
defer graphtest.PutDriver(t)
dir, err := d.Get("test", "")
if err != nil {
t.Fatal(err)
}
defer d.Put("test")
if err := subvolCreate(dir, "subvoltest"); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(path.Join(dir, "subvoltest")); err != nil {
t.Fatal(err)
}
if err := d.Remove("test"); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(path.Join(dir, "subvoltest")); !os.IsNotExist(err) {
t.Fatalf("expected not exist error on nested subvol, got: %v", err)
}
}
func TestBtrfsTeardown(t *testing.T) {
graphtest.PutDriver(t)
}