(t *testing.T)
| 406 | } |
| 407 | |
| 408 | func TestCreateWorkflowMarkdownFile(t *testing.T) { |
| 409 | // Create a temporary directory for testing |
| 410 | tempDir, err := os.MkdirTemp("", "test-new-workflow-*") |
| 411 | if err != nil { |
| 412 | t.Fatalf("Failed to create temp directory: %v", err) |
| 413 | } |
| 414 | defer os.RemoveAll(tempDir) |
| 415 | |
| 416 | // Change to the temp directory |
| 417 | oldWd, err := os.Getwd() |
| 418 | if err != nil { |
| 419 | t.Fatalf("Failed to get current directory: %v", err) |
| 420 | } |
| 421 | defer func() { |
| 422 | if err := os.Chdir(oldWd); err != nil { |
| 423 | t.Logf("Warning: Failed to restore working directory: %v", err) |
| 424 | } |
| 425 | }() |
| 426 | |
| 427 | if err := os.Chdir(tempDir); err != nil { |
| 428 | t.Fatalf("Failed to change to temp directory: %v", err) |
| 429 | } |
| 430 | |
| 431 | tests := []struct { |
| 432 | name string |
| 433 | workflowName string |
| 434 | force bool |
| 435 | expectedError bool |
| 436 | setup func(t *testing.T) |
| 437 | }{ |
| 438 | { |
| 439 | name: "create new workflow", |
| 440 | workflowName: "test-workflow", |
| 441 | force: false, |
| 442 | expectedError: false, |
| 443 | }, |
| 444 | { |
| 445 | name: "fail to overwrite existing workflow without force", |
| 446 | workflowName: "existing-workflow", |
| 447 | force: false, |
| 448 | expectedError: true, |
| 449 | setup: func(t *testing.T) { |
| 450 | // Create an existing workflow file |
| 451 | os.MkdirAll(".github/workflows", 0755) |
| 452 | os.WriteFile(".github/workflows/existing-workflow.md", []byte("test"), 0644) |
| 453 | }, |
| 454 | }, |
| 455 | { |
| 456 | name: "overwrite existing workflow with force", |
| 457 | workflowName: "force-workflow", |
| 458 | force: true, |
| 459 | expectedError: false, |
| 460 | setup: func(t *testing.T) { |
| 461 | // Create an existing workflow file |
| 462 | if err := os.MkdirAll(".github/workflows", 0755); err != nil { |
| 463 | t.Fatalf("Failed to create workflows directory: %v", err) |
| 464 | } |
| 465 | if err := os.WriteFile(".github/workflows/force-workflow.md", []byte("old content"), 0644); err != nil { |
nothing calls this directly
no test coverage detected