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

Function TestAddCommandRequiresArguments

pkg/cli/add_no_args_test.go:15–61  ·  view source on GitHub ↗

TestAddCommandRequiresArguments verifies that the add command requires at least one argument

(t *testing.T)

Source from the content-addressed store, hash-verified

13
14// TestAddCommandRequiresArguments verifies that the add command requires at least one argument
15func TestAddCommandRequiresArguments(t *testing.T) {
16 // Save current directory
17 originalDir, err := os.Getwd()
18 if err != nil {
19 t.Fatalf("Failed to get current directory: %v", err)
20 }
21 defer func() {
22 // Restore original directory
23 if err := os.Chdir(originalDir); err != nil {
24 t.Logf("Warning: Failed to restore directory: %v", err)
25 }
26 }()
27
28 // Create a temporary directory for testing
29 tmpDir := testutil.TempDir(t, "test-*")
30 if err := os.Chdir(tmpDir); err != nil {
31 t.Fatalf("Failed to change to temp dir: %v", err)
32 }
33
34 // Initialize git repo
35 if err := os.MkdirAll(".git", 0755); err != nil {
36 t.Fatalf("Failed to create .git dir: %v", err)
37 }
38
39 // Create add command
40 validateEngine := func(engine string) error { return nil }
41 cmd := NewAddCommand(validateEngine)
42
43 // Set up stderr capture
44 stderr := &bytes.Buffer{}
45 cmd.SetErr(stderr)
46
47 // Try to execute without arguments
48 cmd.SetArgs([]string{})
49
50 // Execute and expect an error
51 err = cmd.Execute()
52 if err == nil {
53 t.Error("Expected error when calling add without arguments, got nil")
54 }
55
56 // Verify the error message mentions workflow specification
57 errMsg := err.Error()
58 if !strings.Contains(errMsg, "missing workflow specification") {
59 t.Errorf("Expected error to mention 'missing workflow specification', got: %s", errMsg)
60 }
61}
62
63// TestAddCommandWithWorkflow verifies that add command works with a workflow specification
64func TestAddCommandWithWorkflow(t *testing.T) {

Callers

nothing calls this directly

Calls 4

TempDirFunction · 0.92
NewAddCommandFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected