MCPcopy Index your code
hub / github.com/cli/cli / TestClientGitDir

Function TestClientGitDir

git/client_test.go:1468–1509  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1466}
1467
1468func TestClientGitDir(t *testing.T) {
1469 tests := []struct {
1470 name string
1471 cmdExitStatus int
1472 cmdStdout string
1473 cmdStderr string
1474 wantCmdArgs string
1475 wantDir string
1476 wantErrorMsg string
1477 }{
1478 {
1479 name: "git dir",
1480 cmdStdout: "/path/to/repo/.git",
1481 wantCmdArgs: `path/to/git rev-parse --git-dir`,
1482 wantDir: "/path/to/repo/.git",
1483 },
1484 {
1485 name: "git error",
1486 cmdExitStatus: 1,
1487 cmdStderr: "git error message",
1488 wantCmdArgs: `path/to/git rev-parse --git-dir`,
1489 wantErrorMsg: "failed to run git: git error message",
1490 },
1491 }
1492 for _, tt := range tests {
1493 t.Run(tt.name, func(t *testing.T) {
1494 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
1495 client := Client{
1496 GitPath: "path/to/git",
1497 commandContext: cmdCtx,
1498 }
1499 dir, err := client.GitDir(context.Background())
1500 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
1501 if tt.wantErrorMsg == "" {
1502 assert.NoError(t, err)
1503 } else {
1504 assert.EqualError(t, err, tt.wantErrorMsg)
1505 }
1506 assert.Equal(t, tt.wantDir, dir)
1507 })
1508 }
1509}
1510
1511func TestClientPathFromRoot(t *testing.T) {
1512 tests := []struct {

Callers

nothing calls this directly

Calls 5

GitDirMethod · 0.95
createCommandContextFunction · 0.85
EqualMethod · 0.80
JoinMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected