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

Function TestAddLocalWorkflow

pkg/cli/add_integration_test.go:284–370  ·  view source on GitHub ↗

TestAddLocalWorkflow tests adding a local workflow file

(t *testing.T)

Source from the content-addressed store, hash-verified

282
283// TestAddLocalWorkflow tests adding a local workflow file
284func TestAddLocalWorkflow(t *testing.T) {
285 setup := setupAddIntegrationTest(t)
286 defer setup.cleanup()
287
288 // Create a local workflow file in a separate "source" directory
289 sourceDir := filepath.Join(setup.tempDir, "source-workflows")
290 err := os.MkdirAll(sourceDir, 0755)
291 require.NoError(t, err, "should create source directory")
292
293 localWorkflowPath := filepath.Join(sourceDir, "test-local-workflow.md")
294 localWorkflowContent := `---
295name: Test Local Workflow
296on:
297 workflow_dispatch:
298permissions:
299 contents: read
300engine: copilot
301---
302
303# Test Local Workflow
304
305This is a test workflow for integration testing.
306
307Please analyze the repository and provide a summary.
308`
309 err = os.WriteFile(localWorkflowPath, []byte(localWorkflowContent), 0644)
310 require.NoError(t, err, "should write local workflow file")
311
312 // Add the local workflow using non-interactive mode
313 cmd := exec.Command(setup.binaryPath, "add", localWorkflowPath, "--verbose")
314 cmd.Dir = setup.tempDir
315 output, err := cmd.CombinedOutput()
316 outputStr := string(output)
317
318 // Log output for debugging
319 t.Logf("Command output:\n%s", outputStr)
320
321 require.NoError(t, err, "add command should succeed: %s", outputStr)
322
323 // Verify .github/workflows directory was created
324 workflowsDir := filepath.Join(setup.tempDir, ".github", "workflows")
325 info, err := os.Stat(workflowsDir)
326 require.NoError(t, err, ".github/workflows directory should exist")
327 assert.True(t, info.IsDir(), ".github/workflows should be a directory")
328
329 // Verify the workflow file was copied
330 destWorkflowFile := filepath.Join(workflowsDir, "test-local-workflow.md")
331 _, err = os.Stat(destWorkflowFile)
332 require.NoError(t, err, "workflow file should exist: %s", destWorkflowFile)
333
334 // Read and verify the workflow content
335 content, err := os.ReadFile(destWorkflowFile)
336 require.NoError(t, err, "should be able to read workflow file")
337 contentStr := string(content)
338
339 // Verify the workflow has expected content (original content preserved)
340 assert.Contains(t, contentStr, "name: Test Local Workflow", "workflow should have original name")
341 assert.Contains(t, contentStr, "workflow_dispatch", "workflow should have original trigger")

Callers

nothing calls this directly

Calls 4

NewImportCacheFunction · 0.92
setupAddIntegrationTestFunction · 0.85

Tested by

no test coverage detected