Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmetin committed Sep 28, 2023
1 parent d6f2e4b commit df939b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions base/commands/migration/start_stages_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package migration_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"sync"
Expand All @@ -26,33 +27,32 @@ func TestMigrationStages(t *testing.T) {
testCases := []struct {
name string
statusMapStateFiles []string
expectedOutput string
expectedErr error
}{
{
name: "successful",
statusMapStateFiles: []string{
"testdata/start/migration_success_initial.json",
"testdata/start/migration_success_completed.json",
},
expectedOutput: "OK Migration completed successfully.",
},
{
name: "failure",
statusMapStateFiles: []string{
"testdata/start/migration_success_initial.json",
"testdata/start/migration_success_failure.json",
},
expectedOutput: "ERROR Failed migrating IMAP: imap5 ...: some error",
expectedErr: errors.New("Failed migrating IMAP: imap5 ...: some error"),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
startMigrationTest(t, tc.expectedOutput, tc.statusMapStateFiles)
startMigrationTest(t, tc.expectedErr, tc.statusMapStateFiles)
})
}
}

func startMigrationTest(t *testing.T, expectedOutput string, statusMapStateFiles []string) {
func startMigrationTest(t *testing.T, expectedErr error, statusMapStateFiles []string) {
tcx := it.TestContext{T: t}
ctx := context.Background()
tcx.Tester(func(tcx it.TestContext) {
Expand All @@ -61,9 +61,10 @@ func startMigrationTest(t *testing.T, expectedOutput string, statusMapStateFiles
defer removeMembersLogs(ctx, ci)
var wg sync.WaitGroup
wg.Add(1)
var execErr error
go tcx.WithReset(func() {
defer wg.Done()
tcx.CLC().Execute(ctx, "start", "dmt-config", "--yes")
execErr = tcx.CLC().Execute(ctx, "start", "dmt-config", "--yes")
})
c := make(chan string, 1)
wg.Add(1)
Expand All @@ -73,7 +74,9 @@ func startMigrationTest(t *testing.T, expectedOutput string, statusMapStateFiles
wg.Add(1)
go migrationRunner(ctx, tcx, mID, &wg, statusMapStateFiles)
wg.Wait()
tcx.AssertStdoutContains(expectedOutput)
if expectedErr != nil {
require.Contains(t, execErr.Error(), expectedErr.Error())
}
tcx.WithReset(func() {
f := fmt.Sprintf("migration_report_%s.txt", mID)
require.Equal(t, true, fileExists(f))
Expand Down
5 changes: 3 additions & 2 deletions base/commands/migration/status_stages_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func noMigrationsStatusTest(t *testing.T) {
tcx.Tester(func(tcx it.TestContext) {
var wg sync.WaitGroup
wg.Add(1)
var execErr error
go tcx.WithReset(func() {
defer wg.Done()
tcx.CLC().Execute(ctx, "status")
execErr = tcx.CLC().Execute(ctx, "status")
})
wg.Wait()
tcx.AssertStdoutContains("there are no migrations are in progress on migration cluster")
require.Contains(t, execErr.Error(), "there are no migrations are in progress on migration cluster")
})
}

Expand Down

0 comments on commit df939b2

Please sign in to comment.