-
Notifications
You must be signed in to change notification settings - Fork 70
/
destroy_test.go
64 lines (52 loc) · 1.53 KB
/
destroy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package zfs_test
import (
"testing"
zfs "github.com/bicomsystems/go-libzfs"
)
func TestDataset_DestroyPromote(t *testing.T) {
zpoolTestPoolCreate(t)
// defer zpoolTestPoolDestroy(t)
var c1, c2 zfs.Dataset
props := make(map[zfs.Prop]zfs.Property)
d, err := zfs.DatasetCreate(TSTPoolName+"/original",
zfs.DatasetTypeFilesystem, make(map[zfs.Prop]zfs.Property))
if err != nil {
t.Errorf("DatasetCreate(\"%s/original\") error: %v", TSTPoolName, err)
return
}
s1, _ := zfs.DatasetSnapshot(d.Properties[zfs.DatasetPropName].Value+"@snap2", false, props)
s2, _ := zfs.DatasetSnapshot(d.Properties[zfs.DatasetPropName].Value+"@snap1", false, props)
c1, err = s1.Clone(TSTPoolName+"/clone1", nil)
if err != nil {
t.Errorf("d.Clone(\"%s/clone1\", props)) error: %v", TSTPoolName, err)
d.Close()
return
}
zfs.DatasetSnapshot(c1.Properties[zfs.DatasetPropName].Value+"@snap1", false, props)
c2, err = s2.Clone(TSTPoolName+"/clone2", nil)
if err != nil {
t.Errorf("c1.Clone(\"%s/clone1\", props)) error: %v", TSTPoolName, err)
d.Close()
c1.Close()
return
}
s2.Close()
zfs.DatasetSnapshot(c2.Properties[zfs.DatasetPropName].Value+"@snap0", false, props)
c1.Close()
c2.Close()
// reopen pool
d.Close()
if d, err = zfs.DatasetOpen(TSTPoolName + "/original"); err != nil {
t.Error("zfs.DatasetOpen")
return
}
if err = d.DestroyPromote(); err != nil {
t.Errorf("DestroyPromote error: %v", err)
d.Close()
return
}
t.Log("Destroy promote completed with success")
d.Close()
zpoolTestPoolDestroy(t)
cleanupVDisks()
}