Skip to content

Commit

Permalink
fix: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gene-redpanda committed Aug 27, 2024
1 parent ff00903 commit b684119
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 17 additions & 6 deletions rpadmin/api_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,30 @@ func (a *AdminAPI) DeleteMigration(ctx context.Context, id int) error {
type MigrationAction int

const (
PrepareAction MigrationAction = iota
ExecuteAction
FinishAction
CancelAction
PrepareMigrationAction MigrationAction = iota
ExecuteMigrationAction
FinishMigrationAction
CancelMigrationAction
)

func (a MigrationAction) String() string {
return [...]string{"prepare", "execute", "finish", "cancel"}[a]
switch a {
case PrepareMigrationAction:
return "prepare"
case ExecuteMigrationAction:
return "execute"
case FinishMigrationAction:
return "finish"
case CancelMigrationAction:
return "cancel"
default:
return ""
}
}

// ExecuteMigration executes a specific action on a migration identified by its ID.
func (a *AdminAPI) ExecuteMigration(ctx context.Context, id int, action MigrationAction) error {
if action < PrepareAction || action > CancelAction {
if action < PrepareMigrationAction || action > CancelMigrationAction {
return fmt.Errorf("invalid action: %s. Must be one of: prepare, execute, finish, cancel", action)
}
return a.sendAny(ctx, http.MethodPost, fmt.Sprintf("%s%d?action=%s", baseMigrationEndpoint, id, action), nil, nil)
Expand Down
6 changes: 3 additions & 3 deletions rpadmin/api_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestExecuteMigration(t *testing.T) {
}
},
id: 123,
action: PrepareAction,
action: PrepareMigrationAction,
},
{
name: "should return error for invalid action",
Expand All @@ -196,7 +196,7 @@ func TestExecuteMigration(t *testing.T) {
}
},
id: 123,
action: ExecuteAction,
action: ExecuteMigrationAction,
expError: true,
},
{
Expand All @@ -209,7 +209,7 @@ func TestExecuteMigration(t *testing.T) {
}
},
id: 123,
action: FinishAction,
action: FinishMigrationAction,
},
}

Expand Down

0 comments on commit b684119

Please sign in to comment.