puk
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"rbd_exporter/RBDFactory"
|
||||
mock "rbd_exporter/mytypes/mock"
|
||||
"testing"
|
||||
|
||||
"github.com/ceph/go-ceph/rbd"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
||||
func TestRBDFactory(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
MockIOContexter := mock.NewMockIOContexter(mockCtrl)
|
||||
MockRBDImager := mock.NewMockRBDImager(mockCtrl)
|
||||
|
||||
rbdName := "test-rbd"
|
||||
expectedImageInfo := &rbd.ImageInfo{
|
||||
Size: 1488,
|
||||
}
|
||||
|
||||
MockIOContexter.EXPECT().GetImage(rbdName).Return(MockRBDImager)
|
||||
MockRBDImager.EXPECT().Open().Return(nil)
|
||||
MockRBDImager.EXPECT().Close().Return(nil)
|
||||
MockRBDImager.EXPECT().Stat().Return(expectedImageInfo,nil)
|
||||
|
||||
|
||||
result,err := RBDFactory.RBDFacroty(MockIOContexter,rbdName)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rbdName, result.Name)
|
||||
assert.Equal(t, expectedImageInfo.Size, result.ImageInfo.Size)
|
||||
}
|
||||
|
||||
|
||||
func TestPoolFactory(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
mockCephConn := mock.NewMockCephConnector(mockCtrl)
|
||||
mockIOCtx := mock.NewMockIOContexter(mockCtrl)
|
||||
mockImage := mock.NewMockRBDImager(mockCtrl)
|
||||
|
||||
|
||||
poolName := "test-pool"
|
||||
imageNames := []string{"rbd1", "rbd2"}
|
||||
expectedImageInfo := &rbd.ImageInfo{Size: 1024}
|
||||
|
||||
mockCephConn.EXPECT().OpenIOContext(poolName).Return(mockIOCtx,nil)
|
||||
mockIOCtx.EXPECT().GetImageNames().Return(imageNames,nil)
|
||||
mockIOCtx.EXPECT().Destroy()
|
||||
|
||||
for _, imageName := range imageNames {
|
||||
mockIOCtx.EXPECT().GetImage(imageName).Return(mockImage)
|
||||
mockImage.EXPECT().Open().Return(nil)
|
||||
mockImage.EXPECT().Close().Return(nil)
|
||||
mockImage.EXPECT().Stat().Return(expectedImageInfo, nil)
|
||||
}
|
||||
|
||||
result, err := RBDFactory.PoolFactory(mockCephConn, poolName)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, poolName, result.Name)
|
||||
assert.True(t, result.HasRBD)
|
||||
assert.Len(t, result.RBDlist, 2)
|
||||
assert.Equal(t, "rbd1", result.RBDlist[0].GetName())
|
||||
assert.Equal(t, "rbd2", result.RBDlist[1].GetName())
|
||||
}
|
||||
Reference in New Issue
Block a user