(t *testing.T)
| 26 | return m.sha, m.err |
| 27 | } |
| 28 | func TestEnsureCopilotSetupSteps(t *testing.T) { |
| 29 | tests := []struct { |
| 30 | name string |
| 31 | existingWorkflow *Workflow |
| 32 | verbose bool |
| 33 | wantErr bool |
| 34 | validateContent func(*testing.T, []byte) |
| 35 | }{ |
| 36 | { |
| 37 | name: "creates new copilot-setup-steps.yml", |
| 38 | verbose: false, |
| 39 | wantErr: false, |
| 40 | validateContent: func(t *testing.T, content []byte) { |
| 41 | if !strings.Contains(string(content), "copilot-setup-steps") { |
| 42 | t.Error("Expected workflow to contain 'copilot-setup-steps' job name") |
| 43 | } |
| 44 | if !strings.Contains(string(content), "install-gh-aw.sh") { |
| 45 | t.Error("Expected workflow to contain install-gh-aw.sh bash script") |
| 46 | } |
| 47 | if !strings.Contains(string(content), "curl -fsSL") { |
| 48 | t.Error("Expected workflow to contain curl command") |
| 49 | } |
| 50 | }, |
| 51 | }, |
| 52 | { |
| 53 | name: "skips update when extension install already exists", |
| 54 | existingWorkflow: &Workflow{ |
| 55 | Name: "Copilot Setup Steps", |
| 56 | On: "workflow_dispatch", |
| 57 | Jobs: map[string]WorkflowJob{ |
| 58 | "copilot-setup-steps": { |
| 59 | RunsOn: "ubuntu-latest", |
| 60 | Steps: []CopilotWorkflowStep{ |
| 61 | { |
| 62 | Name: "Checkout code", |
| 63 | Uses: "actions/checkout@v5", |
| 64 | }, |
| 65 | { |
| 66 | Name: "Install gh-aw extension", |
| 67 | Run: "curl -fsSL https://raw.githubusercontent.com/github/gh-aw/refs/heads/main/install-gh-aw.sh | bash", |
| 68 | }, |
| 69 | }, |
| 70 | }, |
| 71 | }, |
| 72 | }, |
| 73 | verbose: true, |
| 74 | wantErr: false, |
| 75 | validateContent: func(t *testing.T, content []byte) { |
| 76 | // Should not modify existing correct config |
| 77 | count := strings.Count(string(content), "Install gh-aw extension") |
| 78 | if count != 1 { |
| 79 | t.Errorf("Expected exactly 1 occurrence of 'Install gh-aw extension', got %d", count) |
| 80 | } |
| 81 | }, |
| 82 | }, |
| 83 | { |
| 84 | name: "renders instructions for existing workflow without install step", |
| 85 | existingWorkflow: &Workflow{ |
nothing calls this directly
no test coverage detected