TestBuildRemoteWorkflowStatuses tests the helper that builds status entries from GitHub API data when --repo is specified (no local files required).
(t *testing.T)
| 13 | // TestBuildRemoteWorkflowStatuses tests the helper that builds status entries |
| 14 | // from GitHub API data when --repo is specified (no local files required). |
| 15 | func TestBuildRemoteWorkflowStatuses(t *testing.T) { |
| 16 | githubWorkflows := map[string]*GitHubWorkflow{ |
| 17 | "smoke-copilot": {ID: 1, Name: "Smoke Copilot", Path: ".github/workflows/smoke-copilot.lock.yml", State: "active"}, |
| 18 | "weekly-report": {ID: 2, Name: "Weekly Report", Path: ".github/workflows/weekly-report.lock.yml", State: "disabled_manually"}, |
| 19 | "ci-check": {ID: 3, Name: "CI Check", Path: ".github/workflows/ci-check.lock.yml", State: "active"}, |
| 20 | } |
| 21 | |
| 22 | t.Run("returns all workflows when no pattern", func(t *testing.T) { |
| 23 | statuses := buildRemoteWorkflowStatuses("", githubWorkflows, nil) |
| 24 | assert.Len(t, statuses, 3) |
| 25 | }) |
| 26 | |
| 27 | t.Run("filters by pattern case-insensitively", func(t *testing.T) { |
| 28 | statuses := buildRemoteWorkflowStatuses("smoke", githubWorkflows, nil) |
| 29 | assert.Len(t, statuses, 1) |
| 30 | assert.Equal(t, "smoke-copilot", statuses[0].Workflow) |
| 31 | }) |
| 32 | |
| 33 | t.Run("translates disabled_manually to disabled", func(t *testing.T) { |
| 34 | statuses := buildRemoteWorkflowStatuses("weekly", githubWorkflows, nil) |
| 35 | assert.Len(t, statuses, 1) |
| 36 | assert.Equal(t, "disabled", statuses[0].Status) |
| 37 | }) |
| 38 | |
| 39 | t.Run("preserves active state", func(t *testing.T) { |
| 40 | statuses := buildRemoteWorkflowStatuses("ci-check", githubWorkflows, nil) |
| 41 | assert.Len(t, statuses, 1) |
| 42 | assert.Equal(t, "active", statuses[0].Status) |
| 43 | }) |
| 44 | |
| 45 | t.Run("includes run status when ref runs provided", func(t *testing.T) { |
| 46 | latestRuns := map[string]*WorkflowRun{ |
| 47 | "smoke-copilot": {Status: "completed", Conclusion: "success"}, |
| 48 | } |
| 49 | statuses := buildRemoteWorkflowStatuses("smoke", githubWorkflows, latestRuns) |
| 50 | assert.Len(t, statuses, 1) |
| 51 | assert.Equal(t, "completed", statuses[0].RunStatus) |
| 52 | assert.Equal(t, "success", statuses[0].RunConclusion) |
| 53 | }) |
| 54 | |
| 55 | t.Run("empty run status when no matching run", func(t *testing.T) { |
| 56 | latestRuns := map[string]*WorkflowRun{} |
| 57 | statuses := buildRemoteWorkflowStatuses("smoke", githubWorkflows, latestRuns) |
| 58 | assert.Len(t, statuses, 1) |
| 59 | assert.Empty(t, statuses[0].RunStatus) |
| 60 | assert.Empty(t, statuses[0].RunConclusion) |
| 61 | }) |
| 62 | |
| 63 | t.Run("returns empty slice when no workflows match pattern", func(t *testing.T) { |
| 64 | statuses := buildRemoteWorkflowStatuses("nonexistent", githubWorkflows, nil) |
| 65 | assert.Empty(t, statuses) |
| 66 | }) |
| 67 | |
| 68 | t.Run("returns empty slice for empty workflow map", func(t *testing.T) { |
| 69 | statuses := buildRemoteWorkflowStatuses("", map[string]*GitHubWorkflow{}, nil) |
| 70 | assert.Empty(t, statuses) |
| 71 | }) |
| 72 |
nothing calls this directly
no test coverage detected