From 0c7028cdae9d4dd0c53fd5a322d35f0b0c3e9fef Mon Sep 17 00:00:00 2001 From: kmetin Date: Thu, 19 Oct 2023 16:07:12 +0300 Subject: [PATCH] fix Yuce's comments 1 --- base/commands/migration/migration_start.go | 5 ++++- base/commands/migration/start_stages.go | 7 ++++--- base/commands/migration/status_stages.go | 5 ++--- base/commands/migration/status_stages_it_test.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/base/commands/migration/migration_start.go b/base/commands/migration/migration_start.go index 5b430641e..68c5bc033 100644 --- a/base/commands/migration/migration_start.go +++ b/base/commands/migration/migration_start.go @@ -54,7 +54,10 @@ Selected data structures in the source cluster will be migrated to the target cl } ec.PrintlnUnnecessary("") mID := MakeMigrationID() - sts := NewStartStages(ec.Logger(), mID, ec.GetStringArg(argDMTConfig)) + sts, err := NewStartStages(ec.Logger(), mID, ec.GetStringArg(argDMTConfig)) + if err != nil { + return err + } sp := stage.NewFixedProvider(sts.Build(ctx, ec)...) if _, err := stage.Execute(ctx, ec, any(nil), sp); err != nil { return err diff --git a/base/commands/migration/start_stages.go b/base/commands/migration/start_stages.go index ce3b089a8..d2d1842ad 100644 --- a/base/commands/migration/start_stages.go +++ b/base/commands/migration/start_stages.go @@ -5,6 +5,7 @@ package migration import ( "context" "encoding/json" + "errors" "fmt" "github.com/hazelcast/hazelcast-commandline-client/clc/ux/stage" @@ -23,15 +24,15 @@ type StartStages struct { logger log.Logger } -func NewStartStages(logger log.Logger, migrationID, configDir string) *StartStages { +func NewStartStages(logger log.Logger, migrationID, configDir string) (*StartStages, error) { if migrationID == "" { - panic("migrationID is required") + return nil, errors.New("migrationID is required") } return &StartStages{ migrationID: migrationID, configDir: configDir, logger: logger, - } + }, nil } func (st *StartStages) Build(ctx context.Context, ec plug.ExecContext) []stage.Stage[any] { diff --git a/base/commands/migration/status_stages.go b/base/commands/migration/status_stages.go index e6d87fc5c..fbd29ef0f 100644 --- a/base/commands/migration/status_stages.go +++ b/base/commands/migration/status_stages.go @@ -54,12 +54,11 @@ func (st *StatusStages) connectStage(ec plug.ExecContext) func(context.Context, return nil, err } if len(all) == 0 { - return nil, fmt.Errorf("there are no migrations are in progress on migration cluster") + return nil, fmt.Errorf("there are no migrations in progress") } var mip MigrationInProgress m := all[0].(serialization.JSON) - err = json.Unmarshal(m, &mip) - if err != nil { + if err = json.Unmarshal(m, &mip); err != nil { return nil, fmt.Errorf("parsing migration in progress: %w", err) } st.statusMap, err = st.ci.Client().GetMap(ctx, StatusMapName) diff --git a/base/commands/migration/status_stages_it_test.go b/base/commands/migration/status_stages_it_test.go index 715a5b649..a5f7cd859 100644 --- a/base/commands/migration/status_stages_it_test.go +++ b/base/commands/migration/status_stages_it_test.go @@ -46,7 +46,7 @@ func noMigrationsStatusTest(t *testing.T) { execErr = tcx.CLC().Execute(ctx, "status") }) wg.Wait() - require.Contains(t, execErr.Error(), "there are no migrations are in progress on migration cluster") + require.Contains(t, execErr.Error(), "there are no migrations in progress") }) }