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

Function TestClientGitDir

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

Source from the content-addressed store, hash-verified

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