| 18 | ) |
| 19 | |
| 20 | func TestClientCommand(t *testing.T) { |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | repoDir string |
| 24 | gitPath string |
| 25 | wantExe string |
| 26 | wantArgs []string |
| 27 | }{ |
| 28 | { |
| 29 | name: "creates command", |
| 30 | gitPath: "path/to/git", |
| 31 | wantExe: "path/to/git", |
| 32 | wantArgs: []string{"path/to/git", "ref-log"}, |
| 33 | }, |
| 34 | { |
| 35 | name: "adds repo directory configuration", |
| 36 | repoDir: "path/to/repo", |
| 37 | gitPath: "path/to/git", |
| 38 | wantExe: "path/to/git", |
| 39 | wantArgs: []string{"path/to/git", "-C", "path/to/repo", "ref-log"}, |
| 40 | }, |
| 41 | } |
| 42 | for _, tt := range tests { |
| 43 | t.Run(tt.name, func(t *testing.T) { |
| 44 | // Given a client with explicit executable, streams, and repository context |
| 45 | in, out, errOut := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{} |
| 46 | client := Client{ |
| 47 | Stdin: in, |
| 48 | Stdout: out, |
| 49 | Stderr: errOut, |
| 50 | RepoDir: tt.repoDir, |
| 51 | GitPath: tt.gitPath, |
| 52 | } |
| 53 | |
| 54 | // When a Git command is created |
| 55 | cmd, err := client.Command(t.Context(), "ref-log") |
| 56 | |
| 57 | // Then the executable, repository arguments, and streams are wired |
| 58 | require.NoError(t, err) |
| 59 | assert.Equal(t, tt.wantExe, cmd.Path) |
| 60 | assert.Equal(t, tt.wantArgs, cmd.Args) |
| 61 | assert.Same(t, in, cmd.Stdin) |
| 62 | assert.Same(t, out, cmd.Stdout) |
| 63 | assert.Same(t, errOut, cmd.Stderr) |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestClientAuthenticatedCommandScopesCredentialHelperToAllHosts(t *testing.T) { |
| 69 | // Given a client with an explicit gh executable |