MCPcopy
hub / github.com/cli/cli / TestClientToplevelDir

Function TestClientToplevelDir

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

Source from the content-addressed store, hash-verified

1423}
1424
1425func TestClientToplevelDir(t *testing.T) {
1426 tests := []struct {
1427 name string
1428 cmdExitStatus int
1429 cmdStdout string
1430 cmdStderr string
1431 wantCmdArgs string
1432 wantDir string
1433 wantErrorMsg string
1434 }{
1435 {
1436 name: "top level dir",
1437 cmdStdout: "/path/to/repo",
1438 wantCmdArgs: `path/to/git rev-parse --show-toplevel`,
1439 wantDir: "/path/to/repo",
1440 },
1441 {
1442 name: "git error",
1443 cmdExitStatus: 1,
1444 cmdStderr: "git error message",
1445 wantCmdArgs: `path/to/git rev-parse --show-toplevel`,
1446 wantErrorMsg: "failed to run git: git error message",
1447 },
1448 }
1449 for _, tt := range tests {
1450 t.Run(tt.name, func(t *testing.T) {
1451 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
1452 client := Client{
1453 GitPath: "path/to/git",
1454 commandContext: cmdCtx,
1455 }
1456 dir, err := client.ToplevelDir(context.Background())
1457 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
1458 if tt.wantErrorMsg == "" {
1459 assert.NoError(t, err)
1460 } else {
1461 assert.EqualError(t, err, tt.wantErrorMsg)
1462 }
1463 assert.Equal(t, tt.wantDir, dir)
1464 })
1465 }
1466}
1467
1468func TestClientGitDir(t *testing.T) {
1469 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected