// TestValidateVolumeCreate validates validateVolumeCreate() func TestValidateVolumeCreate(t *testing.T) { msg := new(volume.VolCreateRequest) msg.Name = "vol" msg.Bricks = []string{"127.0.0.1:/tmp/b1", "127.0.0.1:/tmp/b2"} c := transaction.NewMockCtx() c.Set("req", msg) defer heketitests.Patch(&volume.ValidateBrickEntriesFunc, func(bricks []brick.Brickinfo, volID uuid.UUID, force bool) (int, error) { return 0, nil }).Restore() defer heketitests.Patch(&peer.GetPeerIDByAddrF, peer.GetPeerIDByAddrMockGood).Restore() vol, e := createVolinfo(msg) tests.Assert(t, e == nil) c.Set("volinfo", vol) e = validateVolumeCreate(c) tests.Assert(t, e == nil) // Mock validateBrickEntries failure defer heketitests.Patch(&volume.ValidateBrickEntriesFunc, func(bricks []brick.Brickinfo, volID uuid.UUID, force bool) (int, error) { return 0, errBad }).Restore() e = validateVolumeCreate(c) tests.Assert(t, e == errBad) }
// TestGenerateVolfiles validates generateVolfiles func TestGenerateVolfiles(t *testing.T) { defer heketitests.Patch(&peer.GetPeerIDByAddrF, peer.GetPeerIDByAddrMockGood).Restore() msg := new(volume.VolCreateRequest) msg.Name = "vol" msg.Bricks = []string{"127.0.0.1:/tmp/b1", "127.0.0.1:/tmp/b2"} vol, e := createVolinfo(msg) c := transaction.NewMockCtx() c.Set("volinfo", vol) defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() defer heketitests.Patch(&volume.AddOrUpdateVolumeFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() e = generateVolfiles(c) tests.Assert(t, e == nil) // Mock volgen failure defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return errBad }).Restore() e = generateVolfiles(c) tests.Assert(t, e == errBad) defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() }
// TestValidateVolumeCreate validates validateVolumeCreate() func TestValidateVolumeCreate(t *testing.T) { msg := new(volume.VolCreateRequest) msg.Name = "vol" msg.Bricks = []string{"127.0.0.1:/tmp/b1", "127.0.0.1:/tmp/b2"} vol, e := createVolume(msg) defer heketitests.Patch(&volume.ExistsFunc, func(name string) bool { return false }).Restore() defer heketitests.Patch(&volume.ValidateBrickEntriesFunc, func(bricks []volume.Brickinfo, volID uuid.UUID, force bool) (int, error) { return 0, nil }).Restore() _, e = validateVolumeCreate(msg, vol) tests.Assert(t, e == nil) // Mock volume exists failure defer heketitests.Patch(&volume.ExistsFunc, func(name string) bool { return true }).Restore() _, e = validateVolumeCreate(msg, vol) tests.Assert(t, e == gderrors.ErrVolExists) // Mock validateBrickEntries failure defer heketitests.Patch(&volume.ExistsFunc, func(name string) bool { return false }).Restore() defer heketitests.Patch(&volume.ValidateBrickEntriesFunc, func(bricks []volume.Brickinfo, volID uuid.UUID, force bool) (int, error) { return 0, errBad }).Restore() _, e = validateVolumeCreate(msg, vol) tests.Assert(t, e == errBad) }
// TestCreateVolume validates createVolume() func TestCreateVolume(t *testing.T) { msg := new(volume.VolCreateRequest) msg.Name = "vol" msg.Bricks = []string{"127.0.0.1:/tmp/b1", "127.0.0.1:/tmp/b2"} vol, e := createVolume(msg) tests.Assert(t, e == nil && vol != nil) // Mock failure in NewBrickEntries(), createVolume() should fail defer heketitests.Patch(&volume.NewBrickEntriesFunc, func(bricks []string) ([]volume.Brickinfo, error) { return nil, errBad }).Restore() vol, e = createVolume(msg) tests.Assert(t, e == errBad) }
// TestCommitVolumeCreate validates commitVolumeCreate() func TestCommitVolumeCreate(t *testing.T) { msg := new(volume.VolCreateRequest) msg.Name = "vol" msg.Bricks = []string{"127.0.0.1:/tmp/b1", "127.0.0.1:/tmp/b2"} vol, e := createVolume(msg) defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() defer heketitests.Patch(&volume.AddOrUpdateVolumeFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() _, e = commitVolumeCreate(vol) tests.Assert(t, e == nil) // Mock volgen failure defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return errBad }).Restore() _, e = commitVolumeCreate(vol) tests.Assert(t, e == errBad) defer heketitests.Patch(&volgen.GenerateVolfileFunc, func(vinfo *volume.Volinfo) error { return nil }).Restore() // Mock store failure defer heketitests.Patch(&volume.AddOrUpdateVolumeFunc, func(vinfo *volume.Volinfo) error { return errBad }).Restore() _, e = commitVolumeCreate(vol) tests.Assert(t, e == errBad) }