test(dashboard): Add unit tests for convoy dashboard fetcher
Add table-driven tests for: - calculateWorkStatus: complete, active, stale, stuck, waiting states - determineCIStatus: pass, fail, pending with various check combinations - determineMergeableStatus: ready, conflict, pending states - determineColorClass: mq-green, mq-yellow, mq-red combinations - getRefineryStatusHint: idle, singular, multiple PR messages - truncateStatusHint: line truncation to 60 chars with ellipsis - parsePolecatSessionName: gt-<rig>-<polecat> parsing - isWorkerSession: worker vs non-worker session detection - parseActivityTimestamp: Unix timestamp parsing from tmux Also refactors inline logic into testable helper functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -710,3 +710,46 @@ func (f *LiveConvoyFetcher) getRefineryStatusHint(mergeQueueCount int) string {
|
||||
}
|
||||
return fmt.Sprintf("Processing %d PRs", mergeQueueCount)
|
||||
}
|
||||
|
||||
// truncateStatusHint truncates a status hint to 60 characters with ellipsis.
|
||||
func truncateStatusHint(line string) string {
|
||||
if len(line) > 60 {
|
||||
return line[:57] + "..."
|
||||
}
|
||||
return line
|
||||
}
|
||||
|
||||
// parsePolecatSessionName parses a tmux session name into rig and polecat components.
|
||||
// Format: gt-<rig>-<polecat> -> (rig, polecat, true)
|
||||
// Returns ("", "", false) if the format is invalid.
|
||||
func parsePolecatSessionName(sessionName string) (rig, polecat string, ok bool) {
|
||||
if !strings.HasPrefix(sessionName, "gt-") {
|
||||
return "", "", false
|
||||
}
|
||||
parts := strings.SplitN(sessionName, "-", 3)
|
||||
if len(parts) != 3 {
|
||||
return "", "", false
|
||||
}
|
||||
return parts[1], parts[2], true
|
||||
}
|
||||
|
||||
// isWorkerSession returns true if the polecat name represents a worker session.
|
||||
// Non-worker sessions: witness, mayor, deacon, boot
|
||||
func isWorkerSession(polecat string) bool {
|
||||
switch polecat {
|
||||
case "witness", "mayor", "deacon", "boot":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// parseActivityTimestamp parses a Unix timestamp string from tmux.
|
||||
// Returns (0, false) for invalid or zero timestamps.
|
||||
func parseActivityTimestamp(s string) (int64, bool) {
|
||||
var unix int64
|
||||
if _, err := fmt.Sscanf(s, "%d", &unix); err != nil || unix <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return unix, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user