(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestGetRequiredSecretsForWorkflow(t *testing.T) { |
| 17 | // Create a temporary directory with test workflow files |
| 18 | tempDir := t.TempDir() |
| 19 | workflowsDir := filepath.Join(tempDir, ".github", "workflows") |
| 20 | err := os.MkdirAll(workflowsDir, 0755) |
| 21 | require.NoError(t, err, "Should create workflows directory") |
| 22 | |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | workflowContent string |
| 26 | expectedSecretName string |
| 27 | expectNil bool |
| 28 | }{ |
| 29 | { |
| 30 | name: "copilot engine workflow", |
| 31 | workflowContent: `--- |
| 32 | engine: copilot |
| 33 | on: push |
| 34 | --- |
| 35 | # Copilot Workflow`, |
| 36 | expectedSecretName: "COPILOT_GITHUB_TOKEN", |
| 37 | expectNil: false, |
| 38 | }, |
| 39 | { |
| 40 | name: "claude engine workflow", |
| 41 | workflowContent: `--- |
| 42 | engine: claude |
| 43 | on: push |
| 44 | --- |
| 45 | # Claude Workflow`, |
| 46 | expectedSecretName: "ANTHROPIC_API_KEY", |
| 47 | expectNil: false, |
| 48 | }, |
| 49 | { |
| 50 | name: "workflow without engine", |
| 51 | workflowContent: `--- |
| 52 | on: push |
| 53 | --- |
| 54 | # No Engine Workflow`, |
| 55 | expectedSecretName: "COPILOT_GITHUB_TOKEN", // Defaults to copilot |
| 56 | expectNil: false, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | for _, tt := range tests { |
| 61 | t.Run(tt.name, func(t *testing.T) { |
| 62 | // Create workflow file with unique name |
| 63 | workflowPath := filepath.Join(workflowsDir, tt.name+".md") |
| 64 | err := os.WriteFile(workflowPath, []byte(tt.workflowContent), 0644) |
| 65 | require.NoError(t, err, "Should write workflow file") |
| 66 | defer os.Remove(workflowPath) |
| 67 | |
| 68 | // Test the function |
| 69 | secrets := getSecretRequirementsForWorkflow(workflowPath) |
| 70 | |
| 71 | if tt.expectNil { |
| 72 | assert.Nil(t, secrets, "Should return nil for workflow without engine") |
| 73 | } else { |
nothing calls this directly
no test coverage detected