ceph-csi/pkg/rbd/controllerserver_test.go

82 lines
1.6 KiB
Go
Raw Normal View History

2019-04-24 23:24:20 +00:00
package rbd
import (
"testing"
"github.com/ceph/ceph-csi/pkg/util"
)
type testCachePersister struct {
volumes map[string]rbdVolume
snapshots map[string]rbdSnapshot
}
func (t *testCachePersister) Create(identifier string, data interface{}) error {
return nil
}
func (t *testCachePersister) Get(identifier string, data interface{}) error {
return nil
}
func (t *testCachePersister) ForAll(pattern string, destObj interface{}, f util.ForAllFunc) error {
switch pattern {
case "csi-rbd-vol-":
for identifier, vol := range t.volumes {
*destObj.(*rbdVolume) = vol
if err := f(identifier); err != nil {
return err
}
}
case "csi-rbd-(.*)-snap-":
for identifier, snap := range t.snapshots {
*destObj.(*rbdSnapshot) = snap
if err := f(identifier); err != nil {
return err
}
}
}
return nil
}
func (t *testCachePersister) Delete(identifier string) error {
return nil
}
func TestLoadExDataFromMetadataStore(t *testing.T) {
cs := &ControllerServer{
MetadataStore: &testCachePersister{
volumes: map[string]rbdVolume{
2019-04-24 23:57:01 +00:00
"item1": {
2019-04-24 23:24:20 +00:00
VolID: "1",
},
2019-04-24 23:57:01 +00:00
"item2": {
2019-04-24 23:24:20 +00:00
VolID: "2",
},
},
snapshots: map[string]rbdSnapshot{
2019-04-24 23:57:01 +00:00
"item1": {
2019-04-24 23:24:20 +00:00
SnapID: "1",
},
2019-04-24 23:57:01 +00:00
"item2": {
2019-04-24 23:24:20 +00:00
SnapID: "2",
},
},
},
}
if err := cs.LoadExDataFromMetadataStore(); err != nil {
t.Error(err)
}
if rbdVolumes["item1"] == rbdVolumes["item2"] {
t.Error("rbd volume entries contain pointer to same volume")
}
if rbdSnapshots["item1"] == rbdSnapshots["item2"] {
t.Error("rbd snapshot entries contain pointer to same snapshot")
}
}