MCPcopy Create free account
hub / github.com/github/gh-aw / TestWorkflowCounting

Function TestWorkflowCounting

pkg/cli/workflows_count_test.go:16–94  ·  view source on GitHub ↗

TestWorkflowCounting tests that only user workflows are counted and displayed

(t *testing.T)

Source from the content-addressed store, hash-verified

14
15// TestWorkflowCounting tests that only user workflows are counted and displayed
16func TestWorkflowCounting(t *testing.T) {
17 // This test verifies that internal workflows (those without .md files) are hidden from users
18 // Only workflows with .md source files are counted and displayed
19
20 // Save current directory
21 originalDir, err := os.Getwd()
22 require.NoError(t, err, "Should get current directory")
23
24 // Change to repository root
25 repoRoot := filepath.Join(originalDir, "..", "..")
26 err = os.Chdir(repoRoot)
27 require.NoError(t, err, "Should change to repository root")
28 defer os.Chdir(originalDir)
29
30 // Get markdown workflow files (simulating what fetchGitHubWorkflows does)
31 mdFiles, err := getMarkdownWorkflowFiles("")
32 if err != nil {
33 t.Skipf("Skipping test: no .github/workflows directory found: %v", err)
34 }
35
36 // Build set of workflow names from .md files
37 mdWorkflowNames := make(map[string]bool)
38 for _, file := range mdFiles {
39 name := extractWorkflowNameFromPath(file)
40 mdWorkflowNames[name] = true
41 }
42
43 // We should have at least some .md files
44 assert.NotEmpty(t, mdWorkflowNames, "Should have at least some .md workflow files")
45
46 // Simulate having some GitHub workflows where not all have .md files
47 // (in reality, this would come from GitHub API)
48 simulatedGitHubWorkflows := make(map[string]*GitHubWorkflow)
49
50 // Add all the .md workflows as "user workflows"
51 for name := range mdWorkflowNames {
52 simulatedGitHubWorkflows[name] = &GitHubWorkflow{
53 Name: name,
54 Path: ".github/workflows/" + name + ".lock.yml",
55 State: "active",
56 }
57 }
58
59 // Add some internal workflows (those without .md files)
60 internalWorkflows := []string{"agentics-maintenance", "ci", "auto-close-parent-issues"}
61 for _, name := range internalWorkflows {
62 // Only add if not already present (to avoid duplicates)
63 if !mdWorkflowNames[name] {
64 simulatedGitHubWorkflows[name] = &GitHubWorkflow{
65 Name: name,
66 Path: ".github/workflows/" + name + ".yml",
67 State: "active",
68 }
69 }
70 }
71
72 // Count user workflows only (internal workflows are not displayed to users)
73 var userWorkflowCount int

Callers

nothing calls this directly

Calls 2

getMarkdownWorkflowFilesFunction · 0.85

Tested by

no test coverage detected