2017-04-26 17:39:16 +02:00
|
|
|
package zfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-04-26 20:25:53 +02:00
|
|
|
"testing"
|
2017-04-26 17:39:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestZFSListHandlesProducesZFSErrorOnNonZeroExit(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
ZFS_BINARY = "./test_helpers/zfs_failer.sh"
|
|
|
|
|
2017-05-01 20:35:04 +02:00
|
|
|
_, err = ZFSList([]string{"fictionalprop"}, "nonexistent/dataset")
|
2017-04-26 17:39:16 +02:00
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
zfsError, ok := err.(ZFSError)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, "error: this is a mock\n", string(zfsError.Stderr))
|
|
|
|
}
|
2017-08-05 21:15:37 +02:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|