TestAddCommandRequiresArguments verifies that the add command requires at least one argument
(t *testing.T)
| 13 | |
| 14 | // TestAddCommandRequiresArguments verifies that the add command requires at least one argument |
| 15 | func 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 |
| 64 | func TestAddCommandWithWorkflow(t *testing.T) { |
nothing calls this directly
no test coverage detected