refactor: split mq.go (1738 lines) into focused modules
- mq.go (400): commands, flags, init, shared helpers - mq_integration.go (606): integration branch create/land/status - mq_status.go (357): status display and formatting - mq_submit.go (219): submit command and branch parsing - mq_list.go (206): list command and filtering Also adds unit tests for helper functions: - formatStatus, getStatusIcon, formatTimeAgo - filterMRsByTarget with edge cases - Test utilities for mocking beads 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
96
internal/cmd/mq_testutil_test.go
Normal file
96
internal/cmd/mq_testutil_test.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/steveyegge/gastown/internal/beads"
|
||||
)
|
||||
|
||||
// mockBeads is a test double for beads.Beads
|
||||
type mockBeads struct {
|
||||
issues map[string]*beads.Issue
|
||||
listFunc func(opts beads.ListOptions) ([]*beads.Issue, error)
|
||||
showFunc func(id string) (*beads.Issue, error)
|
||||
closeFunc func(id string) error
|
||||
}
|
||||
|
||||
func newMockBeads() *mockBeads {
|
||||
return &mockBeads{
|
||||
issues: make(map[string]*beads.Issue),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockBeads) addIssue(issue *beads.Issue) {
|
||||
m.issues[issue.ID] = issue
|
||||
}
|
||||
|
||||
func (m *mockBeads) Show(id string) (*beads.Issue, error) {
|
||||
if m.showFunc != nil {
|
||||
return m.showFunc(id)
|
||||
}
|
||||
if issue, ok := m.issues[id]; ok {
|
||||
return issue, nil
|
||||
}
|
||||
return nil, beads.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *mockBeads) List(opts beads.ListOptions) ([]*beads.Issue, error) {
|
||||
if m.listFunc != nil {
|
||||
return m.listFunc(opts)
|
||||
}
|
||||
var result []*beads.Issue
|
||||
for _, issue := range m.issues {
|
||||
// Apply basic filtering
|
||||
if opts.Type != "" && issue.Type != opts.Type {
|
||||
continue
|
||||
}
|
||||
if opts.Status != "" && issue.Status != opts.Status {
|
||||
continue
|
||||
}
|
||||
result = append(result, issue)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (m *mockBeads) Close(id string) error {
|
||||
if m.closeFunc != nil {
|
||||
return m.closeFunc(id)
|
||||
}
|
||||
if issue, ok := m.issues[id]; ok {
|
||||
issue.Status = "closed"
|
||||
return nil
|
||||
}
|
||||
return beads.ErrNotFound
|
||||
}
|
||||
|
||||
// makeTestIssue creates a test issue with common defaults
|
||||
func makeTestIssue(id, title, issueType, status string) *beads.Issue {
|
||||
return &beads.Issue{
|
||||
ID: id,
|
||||
Title: title,
|
||||
Type: issueType,
|
||||
Status: status,
|
||||
Priority: 2,
|
||||
CreatedAt: "2025-01-01T12:00:00Z",
|
||||
UpdatedAt: "2025-01-01T12:00:00Z",
|
||||
}
|
||||
}
|
||||
|
||||
// makeTestMR creates a test merge request issue
|
||||
func makeTestMR(id, branch, target, worker string, status string) *beads.Issue {
|
||||
desc := beads.FormatMRFields(&beads.MRFields{
|
||||
Branch: branch,
|
||||
Target: target,
|
||||
Worker: worker,
|
||||
SourceIssue: "gt-src-123",
|
||||
Rig: "testrig",
|
||||
})
|
||||
return &beads.Issue{
|
||||
ID: id,
|
||||
Title: "Merge: " + branch,
|
||||
Type: "merge-request",
|
||||
Status: status,
|
||||
Priority: 2,
|
||||
Description: desc,
|
||||
CreatedAt: "2025-01-01T12:00:00Z",
|
||||
UpdatedAt: "2025-01-01T12:00:00Z",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user