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

Function TestFindWorkflowsWithSource_CustomDirectory

pkg/cli/update_command_test.go:435–493  ·  view source on GitHub ↗

TestFindWorkflowsWithSource_CustomDirectory tests that findWorkflowsWithSource works with custom directories

(t *testing.T)

Source from the content-addressed store, hash-verified

433
434// TestFindWorkflowsWithSource_CustomDirectory tests that findWorkflowsWithSource works with custom directories
435func TestFindWorkflowsWithSource_CustomDirectory(t *testing.T) {
436 // Create a temporary directory structure
437 tmpDir := testutil.TempDir(t, "test-*")
438 customWorkflowDir := filepath.Join(tmpDir, "custom", "workflows")
439 if err := os.MkdirAll(customWorkflowDir, 0755); err != nil {
440 t.Fatalf("Failed to create custom workflow directory: %v", err)
441 }
442
443 // Create a workflow file with source field
444 workflowContent := `---
445on: push
446engine: claude
447source: test/repo/workflow.md@v1.0.0
448---
449
450# Test Workflow
451
452Test content.`
453
454 workflowPath := filepath.Join(customWorkflowDir, "test-workflow.md")
455 if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil {
456 t.Fatalf("Failed to write workflow file: %v", err)
457 }
458
459 // Create a workflow file without source field
460 workflowWithoutSource := `---
461on: push
462engine: claude
463---
464
465# Another Workflow
466
467No source field.`
468
469 workflowPath2 := filepath.Join(customWorkflowDir, "no-source.md")
470 if err := os.WriteFile(workflowPath2, []byte(workflowWithoutSource), 0644); err != nil {
471 t.Fatalf("Failed to write workflow file: %v", err)
472 }
473
474 // Test findWorkflowsWithSource with custom directory
475 workflows, err := findWorkflowsWithSource(customWorkflowDir, nil, false)
476 if err != nil {
477 t.Fatalf("Expected no error, got: %v", err)
478 }
479
480 // Should find only one workflow (the one with source field)
481 if len(workflows) != 1 {
482 t.Errorf("Expected to find 1 workflow with source field, got %d", len(workflows))
483 }
484
485 if len(workflows) > 0 {
486 if workflows[0].Name != "test-workflow" {
487 t.Errorf("Expected workflow name 'test-workflow', got '%s'", workflows[0].Name)
488 }
489 if workflows[0].SourceSpec != "test/repo/workflow.md@v1.0.0" {
490 t.Errorf("Expected source spec 'test/repo/workflow.md@v1.0.0', got '%s'", workflows[0].SourceSpec)
491 }
492 }

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
findWorkflowsWithSourceFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected