@@ -4,9 +4,6 @@ package cli
44
55import (
66 "context"
7- "os"
8- "os/exec"
9- "path/filepath"
107 "testing"
118
129 "github.com/spf13/cobra"
@@ -341,78 +338,14 @@ func TestAddCommandArgs(t *testing.T) {
341338 require .NoError (t , err , "Should not error with multiple arguments" )
342339}
343340
344- // TestAddMultipleWorkflowsNameFlag verifies that when multiple workflows are added,
345- // the --name flag applies only to the first workflow and subsequent workflows use their original names.
341+ // TestAddMultipleWorkflowsNameFlag verifies that --name is not allowed when multiple workflows are specified.
346342func TestAddMultipleWorkflowsNameFlag (t * testing.T ) {
347- // Create a temporary directory for testing
348- tmpDir , err := os .MkdirTemp ("" , "gh-aw-add-multiple-workflows-test" )
349- require .NoError (t , err , "Failed to create temp dir" )
350- defer os .RemoveAll (tmpDir )
351-
352- // Change to temp directory
353- originalDir , err := os .Getwd ()
354- require .NoError (t , err , "Failed to get current directory" )
355- defer func () {
356- _ = os .Chdir (originalDir )
357- }()
358-
359- require .NoError (t , os .Chdir (tmpDir ), "Failed to change to temp directory" )
360-
361- // Initialize a git repository
362- if err := exec .Command ("git" , "init" ).Run (); err != nil {
363- t .Skip ("Skipping test - git not available" )
364- }
365- _ = exec .Command ("git" , "config" , "user.email" , "test@example.com" ).Run ()
366- _ = exec .Command ("git" , "config" , "user.name" , "Test User" ).Run ()
367-
368- workflowsDir := filepath .Join (tmpDir , ".github" , "workflows" )
369- require .NoError (t , os .MkdirAll (workflowsDir , 0755 ), "Failed to create workflows directory" )
370-
371- workflowContent := func (name string ) []byte {
372- return []byte ("---\n on: push\n permissions:\n contents: read\n engine: copilot\n ---\n \n # " + name + "\n " )
373- }
374-
375- resolved1 := & ResolvedWorkflow {
376- Spec : & WorkflowSpec {
377- RepoSpec : RepoSpec {RepoSlug : "test/repo" },
378- WorkflowPath : "./workflow-alpha.md" ,
379- WorkflowName : "workflow-alpha" ,
380- },
381- Content : workflowContent ("Alpha" ),
382- SourceInfo : & FetchedWorkflow {
383- Content : workflowContent ("Alpha" ),
384- IsLocal : true ,
385- SourcePath : "./workflow-alpha.md" ,
386- },
387- }
388-
389- resolved2 := & ResolvedWorkflow {
390- Spec : & WorkflowSpec {
391- RepoSpec : RepoSpec {RepoSlug : "test/repo" },
392- WorkflowPath : "./workflow-beta.md" ,
393- WorkflowName : "workflow-beta" ,
394- },
395- Content : workflowContent ("Beta" ),
396- SourceInfo : & FetchedWorkflow {
397- Content : workflowContent ("Beta" ),
398- IsLocal : true ,
399- SourcePath : "./workflow-beta.md" ,
400- },
401- }
402-
403- opts := AddOptions {
404- Name : "custom-name" ,
405- NoGitattributes : true ,
406- }
407-
408- err = addWorkflows ([]* ResolvedWorkflow {resolved1 , resolved2 }, opts )
409- require .NoError (t , err , "addWorkflows should succeed" )
343+ cmd := NewAddCommand (validateEngineStub )
410344
411- // The first workflow should be saved as custom-name.md
412- _ , err = os .Stat (filepath .Join (workflowsDir , "custom-name.md" ))
413- require .NoError (t , err , "First workflow should be saved as custom-name.md" )
345+ // Simulate calling the command with --name and multiple workflow arguments
346+ cmd .SetArgs ([]string {"workflow1" , "workflow2" , "--name" , "custom-name" })
414347
415- // The second workflow should use its original name (workflow-beta.md), not custom-name.md
416- _ , err = os . Stat ( filepath . Join ( workflowsDir , "workflow-beta.md" ) )
417- require . NoError (t , err , "Second workflow should be saved as workflow-beta.md (original name) " )
348+ err := cmd . Execute ()
349+ require . Error ( t , err , "Should error when --name is used with multiple workflows" )
350+ assert . Contains (t , err . Error () , "--name flag cannot be used when adding multiple workflows" , "Error should mention -- name restriction " )
418351}
0 commit comments