2019-08-20 17:04:13 +02:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-10-18 19:21:17 +02:00
|
|
|
"github.com/zrepl/zrepl/internal/platformtest"
|
|
|
|
"github.com/zrepl/zrepl/internal/zfs"
|
2019-08-20 17:04:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetNonexistent(ctx *platformtest.Context) {
|
|
|
|
|
|
|
|
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
|
|
|
DESTROYROOT
|
|
|
|
CREATEROOT
|
|
|
|
+ "foo bar"
|
|
|
|
+ "foo bar@1"
|
|
|
|
`)
|
|
|
|
|
|
|
|
// test raw
|
2020-03-27 00:57:33 +01:00
|
|
|
_, err := zfs.ZFSGetRawAnySource(ctx, fmt.Sprintf("%s/foo bar", ctx.RootDataset), []string{"name"})
|
2019-08-20 17:04:13 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test nonexistent filesystem
|
|
|
|
nonexistent := fmt.Sprintf("%s/nonexistent filesystem", ctx.RootDataset)
|
2020-03-27 00:57:33 +01:00
|
|
|
props, err := zfs.ZFSGetRawAnySource(ctx, nonexistent, []string{"name"})
|
2019-08-20 17:04:13 +02:00
|
|
|
if err == nil {
|
|
|
|
panic(props)
|
|
|
|
}
|
|
|
|
dsne, ok := err.(*zfs.DatasetDoesNotExist)
|
|
|
|
if !ok {
|
|
|
|
panic(err)
|
|
|
|
} else if dsne.Path != nonexistent {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test nonexistent snapshot
|
|
|
|
nonexistent = fmt.Sprintf("%s/foo bar@non existent", ctx.RootDataset)
|
2020-03-27 00:57:33 +01:00
|
|
|
props, err = zfs.ZFSGetRawAnySource(ctx, nonexistent, []string{"name"})
|
2019-08-20 17:04:13 +02:00
|
|
|
if err == nil {
|
|
|
|
panic(props)
|
|
|
|
}
|
|
|
|
dsne, ok = err.(*zfs.DatasetDoesNotExist)
|
|
|
|
if !ok {
|
|
|
|
panic(err)
|
|
|
|
} else if dsne.Path != nonexistent {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:46:14 +02:00
|
|
|
// test nonexistent bookmark
|
|
|
|
nonexistent = fmt.Sprintf("%s/foo bar#non existent", ctx.RootDataset)
|
2020-03-27 00:57:33 +01:00
|
|
|
props, err = zfs.ZFSGetRawAnySource(ctx, nonexistent, []string{"name"})
|
2019-10-14 17:46:14 +02:00
|
|
|
if err == nil {
|
|
|
|
panic(props)
|
|
|
|
}
|
|
|
|
dsne, ok = err.(*zfs.DatasetDoesNotExist)
|
|
|
|
if !ok {
|
|
|
|
panic(err)
|
|
|
|
} else if dsne.Path != nonexistent {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-08-20 17:04:13 +02:00
|
|
|
}
|