Пример #1
0
func TestSubVolumeCreateValidation(t *testing.T) {
	subvol := btrfs.NewIoctl().Subvolume()
	cmd := subvol.Create()
	err := cmd.Execute()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "destination is empty")

	cmd = subvol.Create()
	err = cmd.Destination(strings.Repeat("s", 512)).Execute()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "subvolume name too long")
	assert.Contains(t, err.Error(), "max length is 255")

	// cmd = subvol.Create()
	// err = cmd.Name("/name").Execute()
	// assert.Error(t, err)
	// assert.Contains(t, err.Error(), "incorrect subvolume name '/name'")

	cmd = subvol.Create()
	err = cmd.Destination(".").Execute()
	assert.Contains(t, err.Error(), "incorrect subvolume name '.'")

	cmd = subvol.Create()
	err = cmd.Destination("..").Execute()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "incorrect subvolume name '..'")
}
Пример #2
0
func TestSubVolumeCreate(t *testing.T) {
	subvol := btrfs.NewIoctl().Subvolume()
	cmd := subvol.Create()
	assert.NotNil(t, cmd)

	err := cmd.QuotaGroups("1", "2", "3").Destination(filepath.Join(mount, "volume2")).Execute()
	assert.NoError(t, err)

	ctx := cmd.(*subvolCreate)
	assert.Equal(t, ctx.qgroups, []string{"1", "2", "3"})
	assert.Equal(t, ctx.dest, filepath.Join(mount, "volume2"))
}
Пример #3
0
func TestSubVolumeFindNew(t *testing.T) {
	repo := filepath.Join(mount, "repo_TestSubVolumeFindNew")

	subvol := btrfs.NewIoctl().Subvolume()
	err := subvol.Create().Destination(repo).Execute()
	assert.NoError(t, err)

	master := filepath.Join(repo, "master")
	err = subvol.Create().Destination(master).Execute()
	assert.NoError(t, err)

	commit0 := filepath.Join(repo, "commit0")
	err = subvol.Snapshot().Source(master).Destination(commit0).Execute()
	assert.NoError(t, err)
}
Пример #4
0
func TestSubVolumeDelete(t *testing.T) {
	repo := filepath.Join(mount, "repo_TestSubVolumeDelete")

	subvol := btrfs.NewIoctl().Subvolume()
	err := subvol.Create().Destination(repo).Execute()
	assert.NoError(t, err)
	_, err = os.Stat(repo)
	assert.NoError(t, err)

	err = subvol.Delete().Destination(repo).Execute()
	assert.NoError(t, err)
	_, err = os.Stat(repo)
	assert.Error(t, err)
	assert.True(t, os.IsNotExist(err))
}
Пример #5
0
func TestSubVolumeSnapshot(t *testing.T) {
	subvol := btrfs.NewIoctl().Subvolume()
	err := subvol.Create().Destination(filepath.Join(mount, "volume1")).Execute()
	assert.NoError(t, err)

	// pass dest/name
	cmdSnapshot := subvol.Snapshot().Source(filepath.Join(mount, "volume1")).Destination(filepath.Join(mount, "snapshot"))
	err = cmdSnapshot.Execute()
	assert.NoError(t, err)

	fi, err := os.Stat(filepath.Join(mount, "snapshot"))
	assert.NoError(t, err)
	assert.True(t, fi.IsDir())

	// pass only dest directory
	os.MkdirAll(filepath.Join(mount, "newsnapsdir"), 0700)
	cmdSnapshot = subvol.Snapshot().Source(filepath.Join(mount, "volume1")).Destination(filepath.Join(mount, "newsnapsdir/"))
	err = cmdSnapshot.Execute()
	assert.NoError(t, err)

	fi, err = os.Stat(filepath.Join(mount, "newsnapsdir/volume1"))
	assert.NoError(t, err)
	assert.True(t, fi.IsDir())
}
Пример #6
0
func TestSubVolumeList(t *testing.T) {
	subvol := btrfs.NewIoctl().Subvolume()

	_, err := subvol.List().Path("/mnt/btrfs-sandbox/").Execute()
	assert.NoError(t, err)
}