zrepl/replication/pdu/pdu_test.go

69 lines
1.1 KiB
Go
Raw Normal View History

package pdu
import (
"github.com/stretchr/testify/assert"
2018-08-25 21:30:25 +02:00
"testing"
2018-09-05 02:01:46 +02:00
"time"
)
func TestFilesystemVersion_RelName(t *testing.T) {
type TestCase struct {
2018-08-25 21:30:25 +02:00
In FilesystemVersion
Out string
Panic bool
}
2018-09-05 02:01:46 +02:00
creat := FilesystemVersionCreation(time.Now())
tcs := []TestCase{
{
In: FilesystemVersion{
Type: FilesystemVersion_Snapshot,
Name: "foobar",
2018-09-05 02:01:46 +02:00
Creation: creat,
},
Out: "@foobar",
},
{
In: FilesystemVersion{
Type: FilesystemVersion_Bookmark,
Name: "foobar",
2018-09-05 02:01:46 +02:00
Creation: creat,
},
Out: "#foobar",
},
{
In: FilesystemVersion{
Type: 2342,
Name: "foobar",
2018-09-05 02:01:46 +02:00
Creation: creat,
},
Panic: true,
},
}
for _, tc := range tcs {
if tc.Panic {
assert.Panics(t, func() {
tc.In.RelName()
})
} else {
o := tc.In.RelName()
assert.Equal(t, tc.Out, o)
}
}
}
func TestFilesystemVersion_ZFSFilesystemVersion(t *testing.T) {
empty := &FilesystemVersion{}
2018-09-05 02:01:46 +02:00
_, err:= empty.ZFSFilesystemVersion()
assert.Error(t, err)
2018-08-25 21:30:25 +02:00
dateInvalid := &FilesystemVersion{Creation: "foobar"}
2018-09-05 02:01:46 +02:00
_, err = dateInvalid.ZFSFilesystemVersion()
assert.Error(t, err)
}