Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage for: factory/bootstrap #5139

Merged
merged 15 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,9 @@ var ErrNilPersistentHandler = errors.New("nil persistent handler")

// ErrNilGenesisNodesSetupHandler signals that a nil genesis nodes setup handler has been provided
var ErrNilGenesisNodesSetupHandler = errors.New("nil genesis nodes setup handler")

// ErrNilLogger signals that a nil logger instance has been provided
var ErrNilLogger = errors.New("nil logger")

// ErrNilShuffleOutCloser signals that a nil shuffler out closer has been provided
var ErrNilShuffleOutCloser = errors.New("nil shuffler out closer")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we go with shuffler out or with shuffle out ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, typo

10 changes: 5 additions & 5 deletions factory/bootstrap/bootstrapComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ func NewBootstrapComponentsFactory(args BootstrapComponentsFactoryArgs) (*bootst
if args.WorkingDir == "" {
return nil, errors.ErrInvalidWorkingDir
}
if check.IfNil(args.StatusCoreComponents) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return nil, errors.ErrNilStatusCoreComponents
}
if check.IfNil(args.StatusCoreComponents.AppStatusHandler()) {
return nil, errors.ErrNilAppStatusHandler
}
Expand Down Expand Up @@ -165,12 +162,15 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) {
return nil, err
}

unitOpener := createUnitOpener(
unitOpener, err := createUnitOpener(
bootstrapDataProvider,
latestStorageDataProvider,
storage.DefaultEpochString,
storage.DefaultShardString,
)
if err != nil {
return nil, err
}

dataSyncerFactory := bootstrap.NewScheduledDataSyncerFactory()

Expand Down Expand Up @@ -337,7 +337,7 @@ func createUnitOpener(
latestDataFromStorageProvider storage.LatestStorageDataProviderHandler,
defaultEpochString string,
defaultShardString string,
) storage.UnitOpenerHandler {
) (storage.UnitOpenerHandler, error) {
argsStorageUnitOpener := storageFactory.ArgsNewOpenStorageUnits{
BootstrapDataProvider: bootstrapDataProvider,
LatestStorageDataProvider: latestDataFromStorageProvider,
Expand Down
35 changes: 32 additions & 3 deletions factory/bootstrap/bootstrapComponentsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"testing"

errorsErd "github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/factory/bootstrap"
componentsMock "github.com/multiversx/mx-chain-go/testscommon/components"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -31,18 +33,22 @@ func TestNewBootstrapComponentsFactory_NilFactory(t *testing.T) {
require.Equal(t, errorsErd.ErrNilBootstrapComponentsFactory, err)
}

func TestManagedBootstrapComponents_CheckSubcomponentsNoCreate(t *testing.T) {
func TestManagedBootstrapComponents_MethodsNoCreate(t *testing.T) {
t.Parallel()

args := componentsMock.GetBootStrapFactoryArgs()
bcf, _ := bootstrap.NewBootstrapComponentsFactory(args)
mbc, _ := bootstrap.NewManagedBootstrapComponents(bcf)
err := mbc.CheckSubcomponents()

require.Equal(t, errorsErd.ErrNilBootstrapComponentsHolder, err)

assert.Nil(t, mbc.EpochStartBootstrapper())
assert.Nil(t, mbc.EpochBootstrapParams())
assert.Nil(t, mbc.Close())
assert.Equal(t, factory.BootstrapComponentsName, mbc.String())
}

func TestManagedBootstrapComponents_Create(t *testing.T) {
func TestManagedBootstrapComponents_MethodsCreate(t *testing.T) {
t.Parallel()

args := componentsMock.GetBootStrapFactoryArgs()
Expand All @@ -54,6 +60,17 @@ func TestManagedBootstrapComponents_Create(t *testing.T) {

err = mbc.CheckSubcomponents()
require.Nil(t, err)

assert.NotNil(t, mbc.EpochStartBootstrapper())
params := mbc.EpochBootstrapParams()
require.NotNil(t, mbc)
assert.Equal(t, uint32(0), params.Epoch())
assert.Equal(t, uint32(0), params.SelfShardID())
assert.Equal(t, uint32(2), params.NumOfShards())
assert.Nil(t, params.NodesConfig())

assert.Nil(t, mbc.Close())
assert.Equal(t, factory.BootstrapComponentsName, mbc.String())
}

func TestManagedBootstrapComponents_CreateNilInternalMarshalizer(t *testing.T) {
Expand Down Expand Up @@ -84,3 +101,15 @@ func TestManagedBootstrapComponents_Close(t *testing.T) {
_ = mbc.Close()
require.Nil(t, mbc.EpochBootstrapParams())
}

func TestManagedBootstrapComponents_IsInterfaceNil(t *testing.T) {
t.Parallel()

mbc, _ := bootstrap.NewManagedBootstrapComponents(nil)
require.True(t, mbc.IsInterfaceNil())

args := componentsMock.GetBootStrapFactoryArgs()
bcf, _ := bootstrap.NewBootstrapComponentsFactory(args)
mbc, _ = bootstrap.NewManagedBootstrapComponents(bcf)
require.False(t, mbc.IsInterfaceNil())
}