diff --git a/base/commands/migration/start_stages_it_test.go b/base/commands/migration/start_stages_it_test.go index 03ea2f8c..e0f842e3 100644 --- a/base/commands/migration/start_stages_it_test.go +++ b/base/commands/migration/start_stages_it_test.go @@ -16,7 +16,6 @@ import ( "github.com/hazelcast/hazelcast-commandline-client/base/commands/migration" . "github.com/hazelcast/hazelcast-commandline-client/internal/check" "github.com/hazelcast/hazelcast-commandline-client/internal/it" - hz "github.com/hazelcast/hazelcast-go-client" "github.com/hazelcast/hazelcast-go-client/serialization" "github.com/stretchr/testify/require" ) @@ -48,7 +47,7 @@ func startTest_Successful(t *testing.T) { c := make(chan string, 1) go findMigrationID(ctx, tcx, c) migrationID := <-c - fileNames := successfulRunner(t, migrationID, tcx, ctx) + migrationReport := successfulRunner(migrationID, tcx, ctx) wg.Wait() tcx.AssertStdoutContains(fmt.Sprintf(` Hazelcast Data Migration Tool v5.3.0 @@ -63,14 +62,12 @@ first message second message last message status report -migration report saved to file: migration_report_%s +migration report saved to file: migration_report_%s.txt OK [3/3] Migrated the cluster. OK Migration completed successfully.`, migrationID)) tcx.WithReset(func() { - for _, n := range fileNames { - require.Equal(t, true, fileExists(n)) - } + require.Equal(t, true, fileExists(migrationReport)) }) }) } @@ -82,7 +79,7 @@ func startTest_Failure(t *testing.T) { go tcx.WithReset(func() { tcx.CLC().Execute(ctx, "start", "dmt-config", "--yes") }) - failureRunner(tcx, ctx) + migrationReport := failureRunner(tcx, ctx) tcx.AssertStdoutContains(` Hazelcast Data Migration Tool v5.3.0 (c) 2023 Hazelcast, Inc. @@ -95,6 +92,9 @@ first message OK [2/3] Started the migration. second message fail status report`) + tcx.WithReset(func() { + require.Equal(t, true, fileExists(migrationReport)) + }) }) } @@ -109,14 +109,7 @@ func fileExists(filename string) bool { return true } -func successfulRunner(t *testing.T, migrationID string, tcx it.TestContext, ctx context.Context) []string { - var fileNames []string - for _, m := range hz.NewClientInternal(tcx.Client).OrderedMembers() { - l := MustValue(tcx.Client.GetList(ctx, migration.DebugLogsListPrefix+m.UUID.String())) - require.Equal(t, true, MustValue(l.AddAll(ctx, "log1\n", "log2\n", "log3\n"))) - fileNames = append(fileNames, fmt.Sprintf("%s%s.log", migration.DebugLogsListPrefix, m.UUID.String())) - } - fileNames = append(fileNames, fmt.Sprintf("migration_report_%s", migrationID)) +func successfulRunner(migrationID string, tcx it.TestContext, ctx context.Context) string { topic := MustValue(tcx.Client.GetTopic(ctx, migration.MakeUpdateTopicName(migrationID))) msg := MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusInProgress, Message: "first message", CompletionPercentage: 10})) Must(topic.Publish(ctx, serialization.JSON(msg))) @@ -131,10 +124,10 @@ func successfulRunner(t *testing.T, migrationID string, tcx it.TestContext, ctx Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b))) msg = MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusComplete, Message: "last message", CompletionPercentage: 100})) Must(topic.Publish(ctx, serialization.JSON(msg))) - return fileNames + return fmt.Sprintf("migration_report_%s.txt", migrationID) } -func failureRunner(tcx it.TestContext, ctx context.Context) { +func failureRunner(tcx it.TestContext, ctx context.Context) string { c := make(chan string, 1) go findMigrationID(ctx, tcx, c) migrationID := <-c @@ -150,6 +143,7 @@ func failureRunner(tcx it.TestContext, ctx context.Context) { Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b))) msg = MustValue(json.Marshal(migration.UpdateMessage{Status: migration.StatusFailed, Message: "second message", CompletionPercentage: 60})) Must(topic.Publish(ctx, serialization.JSON(msg))) + return fmt.Sprintf("migration_report_%s.txt", migrationID) } func findMigrationID(ctx context.Context, tcx it.TestContext, c chan string) {