zrepl/replication/logic/pdu/pdu_test.go

70 lines
1.1 KiB
Go
Raw Normal View History

package pdu
import (
2018-08-25 21:30:25 +02:00
"testing"
2018-09-05 02:01:46 +02:00
"time"
2019-03-22 19:41:12 +01:00
"github.com/stretchr/testify/assert"
)
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{
2019-03-22 19:41:12 +01:00
Type: FilesystemVersion_Snapshot,
Name: "foobar",
2018-09-05 02:01:46 +02:00
Creation: creat,
},
Out: "@foobar",
},
{
In: FilesystemVersion{
2019-03-22 19:41:12 +01:00
Type: FilesystemVersion_Bookmark,
Name: "foobar",
2018-09-05 02:01:46 +02:00
Creation: creat,
},
Out: "#foobar",
},
{
In: FilesystemVersion{
2019-03-22 19:41:12 +01:00
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{}
2019-03-22 19:41:12 +01:00
_, err := empty.ZFSFilesystemVersion()
2018-09-05 02:01:46 +02:00
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)
}