zrepl/zfs/zfs_test.go

31 lines
746 B
Go
Raw Normal View History

package zfs
import (
"github.com/stretchr/testify/assert"
2017-04-26 20:25:53 +02:00
"testing"
)
func TestZFSListHandlesProducesZFSErrorOnNonZeroExit(t *testing.T) {
var err error
ZFS_BINARY = "./test_helpers/zfs_failer.sh"
_, err = ZFSList([]string{"fictionalprop"}, "nonexistent/dataset")
assert.Error(t, err)
zfsError, ok := err.(ZFSError)
assert.True(t, ok)
assert.Equal(t, "error: this is a mock\n", string(zfsError.Stderr))
}
func TestDatasetPathTrimNPrefixComps(t *testing.T) {
p, err := NewDatasetPath("foo/bar/a/b")
assert.Nil(t, err)
p.TrimNPrefixComps(2)
assert.True(t, p.Equal(toDatasetPath("a/b")))
p.TrimNPrefixComps((2))
assert.True(t, p.Empty())
p.TrimNPrefixComps((1))
assert.True(t, p.Empty(), "empty trimming shouldn't do harm")
}