Skip to content

Commit ec1bb91

Browse files
committed
refactor: port status page migrate commands to SDK + RunContext
Replaces the CLI-local raw-HTTP transport introduced by #1 with the flashduty-sdk v0.7.0 methods and routes the 4 migrate subcommands through the RunContext / runCommand pattern used by every other command. Changes: - Bump flashduty-sdk from v0.6.0 to v0.7.0 (adds status page migration methods). - Extend flashdutyClient interface with StartStatusPageMigration, StartStatusPageEmailSubscriberMigration, GetStatusPageMigrationStatus, CancelStatusPageMigration. - Add default mockClient stubs for the four new interface methods. - Rewrite internal/cli/status_page_migrate.go (~590 lines to ~280): delete statusPageMigrationAPI, statusPageMigrationService, the CLI-local migration transport, manual sanitization, and duplicate local types. Each cobra command now uses runCommand(cmd, args, func(ctx *RunContext) error {...}) and delegates to ctx.Client.*. Print helpers rewired from flagJSON / newPrinter() globals to ctx.JSON / ctx.Printer / ctx.Writer. - Rewrite internal/cli/status_page_migrate_test.go (387 lines to ~340): replace httptest-backed transport tests with newClientFn mock-swap tests using execCommand, matching the pattern established in command_test.go. One httptest-backed integration test per SDK method is not kept here because the flashduty-sdk repo owns wire-format tests now. Post-review fixes (independent reviews from go-reviewer + Codex): - Nil-guard mock methods so tests overriding a subset do not panic. - Assert "atlassian" substring in the unsupported-source error so the supported list cannot silently drift. - Emit both "command" (PR #1 schema) and "next_command" in cancel --json output to preserve the shipped JSON contract. - Move validateMigrationSource before runCommand so an invalid --from fails with the source error before any client/auth work, matching PR #1 ordering. Add two tests locking the ordering. Command output and JSON schemas remain compatible with PR #1. The file internal/cli/status_page_migrate.go is no longer an architectural outlier: 100% of the CLI now flows through ctx.Client. Verification: - go test -race -count=1 ./... green - go test -tags=e2e ./e2e/... green (24.4s) - gofmt, goimports, go vet clean - Coverage on ported commands: 80-100%.
1 parent bf81170 commit ec1bb91

6 files changed

Lines changed: 401 additions & 661 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/flashcatcloud/flashduty-cli
33
go 1.25.1
44

55
require (
6-
github.com/flashcatcloud/flashduty-sdk v0.6.0
6+
github.com/flashcatcloud/flashduty-sdk v0.7.0
77
github.com/spf13/cobra v1.10.2
88
golang.org/x/term v0.42.0
99
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2-
github.com/flashcatcloud/flashduty-sdk v0.6.0 h1:2dzJJ5s7Wgq7KWbsnbGMSo0+yN8yuNMVc50M+dtF8rU=
3-
github.com/flashcatcloud/flashduty-sdk v0.6.0/go.mod h1:dG4eJfdZaj4jNBMwEexbfK/3PmcIMhNeJ88L/DcZzUY=
2+
github.com/flashcatcloud/flashduty-sdk v0.7.0 h1:yPW8ghyHB60/34fz5sBITXhMWtbsm2mxYVFORgs+jpE=
3+
github.com/flashcatcloud/flashduty-sdk v0.7.0/go.mod h1:dG4eJfdZaj4jNBMwEexbfK/3PmcIMhNeJ88L/DcZzUY=
44
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
55
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
66
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

internal/cli/command_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ func (m *mockClient) SearchAuditLogs(context.Context, *flashduty.SearchAuditLogs
191191
return nil, fmt.Errorf("mockClient: SearchAuditLogs not implemented")
192192
}
193193

194+
func (m *mockClient) StartStatusPageMigration(context.Context, *flashduty.StartStatusPageMigrationInput) (*flashduty.StartStatusPageMigrationOutput, error) {
195+
return nil, fmt.Errorf("mockClient: StartStatusPageMigration not implemented")
196+
}
197+
198+
func (m *mockClient) StartStatusPageEmailSubscriberMigration(context.Context, *flashduty.StartStatusPageEmailSubscriberMigrationInput) (*flashduty.StartStatusPageMigrationOutput, error) {
199+
return nil, fmt.Errorf("mockClient: StartStatusPageEmailSubscriberMigration not implemented")
200+
}
201+
202+
func (m *mockClient) GetStatusPageMigrationStatus(context.Context, string) (*flashduty.StatusPageMigrationJob, error) {
203+
return nil, fmt.Errorf("mockClient: GetStatusPageMigrationStatus not implemented")
204+
}
205+
206+
func (m *mockClient) CancelStatusPageMigration(context.Context, string) error {
207+
return fmt.Errorf("mockClient: CancelStatusPageMigration not implemented")
208+
}
209+
194210
// saveAndResetGlobals saves the current state of all global vars that commands
195211
// mutate, resets them to safe defaults, and returns a restore function for
196212
// t.Cleanup.

internal/cli/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ type flashdutyClient interface {
6868
QueryInsightIncidentList(ctx context.Context, input *flashduty.QueryInsightIncidentListInput) (*flashduty.QueryInsightIncidentListOutput, error)
6969
QueryNotificationTrend(ctx context.Context, input *flashduty.QueryNotificationTrendInput) (*flashduty.QueryNotificationTrendOutput, error)
7070
SearchAuditLogs(ctx context.Context, input *flashduty.SearchAuditLogsInput) (*flashduty.SearchAuditLogsOutput, error)
71+
72+
// === PHASE 4: Status Page Migration ===
73+
StartStatusPageMigration(ctx context.Context, input *flashduty.StartStatusPageMigrationInput) (*flashduty.StartStatusPageMigrationOutput, error)
74+
StartStatusPageEmailSubscriberMigration(ctx context.Context, input *flashduty.StartStatusPageEmailSubscriberMigrationInput) (*flashduty.StartStatusPageMigrationOutput, error)
75+
GetStatusPageMigrationStatus(ctx context.Context, jobID string) (*flashduty.StatusPageMigrationJob, error)
76+
CancelStatusPageMigration(ctx context.Context, jobID string) error
7177
}
7278

7379
// newClientFn creates a flashdutyClient. Override in tests to inject a mock.

0 commit comments

Comments
 (0)