Files
beads/cmd/bd/stale_test.go
Steve Yegge 8023a6cd6c Improve test coverage to 57.7% (+13.5%)
Added comprehensive test coverage for previously untested commands:
- version_test.go: Plain text and JSON version output
- list_test.go: All filter operations and label normalization
- export_test.go: JSONL export with labels & dependencies
- stale_test.go: Duration formatting and stale issue detection
- comments_test.go: Comment management and error handling
- delete_test.go: Batch deletion helpers
- metrics_test.go: RPC metrics recording and snapshots

Coverage improvement:
- Overall: 44.2% → 57.7% (+13.5%)
- cmd/bd: 17.9% → 19.8% (+1.9%)
- internal/rpc: 45.2% → 45.8% (+0.6%)

All tests passing with no new linter warnings.

Amp-Thread-ID: https://ampcode.com/threads/T-1ee1734e-0164-4c6f-834e-cb8051d14302
Co-authored-by: Amp <amp@ampcode.com>
2025-10-24 00:56:18 -07:00

83 lines
1.8 KiB
Go

package main
import (
"testing"
"time"
)
func TestFormatDuration(t *testing.T) {
tests := []struct {
name string
duration time.Duration
want string
}{
{
name: "less than a minute",
duration: 45 * time.Second,
want: "45 seconds",
},
{
name: "exactly one minute",
duration: 60 * time.Second,
want: "1 minutes",
},
{
name: "several minutes",
duration: 5 * time.Minute,
want: "5 minutes",
},
{
name: "one hour",
duration: 60 * time.Minute,
want: "1.0 hours",
},
{
name: "several hours",
duration: 3*time.Hour + 30*time.Minute,
want: "3.5 hours",
},
{
name: "one day",
duration: 24 * time.Hour,
want: "1.0 days",
},
{
name: "multiple days",
duration: 3*24*time.Hour + 12*time.Hour,
want: "3.5 days",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := formatDuration(tt.duration)
if got != tt.want {
t.Errorf("formatDuration(%v) = %q, want %q", tt.duration, got, tt.want)
}
})
}
}
func TestStaleIssueInfo(t *testing.T) {
// Test that StaleIssueInfo struct can be created and serialized
info := &StaleIssueInfo{
IssueID: "bd-42",
IssueTitle: "Test Issue",
IssuePriority: 1,
ExecutorInstanceID: "exec-123",
ExecutorStatus: "stopped",
ExecutorHostname: "localhost",
ExecutorPID: 12345,
LastHeartbeat: time.Now().Add(-10 * time.Minute),
ClaimedAt: time.Now().Add(-30 * time.Minute),
ClaimedDuration: "30 minutes",
}
if info.IssueID != "bd-42" {
t.Errorf("Expected IssueID bd-42, got %s", info.IssueID)
}
if info.ExecutorStatus != "stopped" {
t.Errorf("Expected ExecutorStatus stopped, got %s", info.ExecutorStatus)
}
}