MCPcopy Create free account
hub / github.com/cli/cli / TestClientGitDir

Function TestClientGitDir

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

Source from the content-addressed store, hash-verified

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