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

Function TestAddEngineToWorkflow

pkg/cli/add_source_test.go:184–307  ·  view source on GitHub ↗

TestAddEngineToWorkflow tests the addEngineToWorkflow function

(t *testing.T)

Source from the content-addressed store, hash-verified

182
183// TestAddEngineToWorkflow tests the addEngineToWorkflow function
184func TestAddEngineToWorkflow(t *testing.T) {
185 tests := []struct {
186 name string
187 content string
188 engine string
189 expectError bool
190 checkEngine bool
191 expectBlankLine bool // expect blank line after engine declaration
192 }{
193 {
194 name: "add_new_engine_field_has_trailing_blank_line",
195 content: `---
196on: push
197permissions:
198 contents: read
199---
200
201# Test Workflow`,
202 engine: "claude",
203 expectError: false,
204 checkEngine: true,
205 expectBlankLine: true,
206 },
207 {
208 name: "update_existing_engine_field_no_extra_blank_line",
209 content: `---
210on: push
211engine: codex
212---
213
214# Test Workflow`,
215 engine: "claude",
216 expectError: false,
217 checkEngine: true,
218 expectBlankLine: false, // updating existing field doesn't add a blank line
219 },
220 }
221
222 for _, tt := range tests {
223 t.Run(tt.name, func(t *testing.T) {
224 result, err := addEngineToWorkflow(tt.content, tt.engine)
225
226 if tt.expectError && err == nil {
227 t.Errorf("addEngineToWorkflow() expected error, got nil")
228 return
229 }
230
231 if !tt.expectError && err != nil {
232 t.Errorf("addEngineToWorkflow() error = %v", err)
233 return
234 }
235
236 if !tt.expectError && tt.checkEngine {
237 // Verify that the engine field is present with the correct value
238 if !strings.Contains(result, "engine: "+tt.engine) {
239 t.Errorf("addEngineToWorkflow() result does not contain 'engine: %s'. Result:\n%s", tt.engine, result)
240 }
241

Callers

nothing calls this directly

Calls 4

addEngineToWorkflowFunction · 0.85
addSourceToWorkflowFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected