MCPcopy
hub / github.com/cli/cli / TestClientCheckoutNewBranch

Function TestClientCheckoutNewBranch

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

Source from the content-addressed store, hash-verified

1384}
1385
1386func TestClientCheckoutNewBranch(t *testing.T) {
1387 tests := []struct {
1388 name string
1389 cmdExitStatus int
1390 cmdStdout string
1391 cmdStderr string
1392 wantCmdArgs string
1393 wantErrorMsg string
1394 }{
1395 {
1396 name: "checkout new branch",
1397 wantCmdArgs: `path/to/git checkout -b trunk --track origin/trunk`,
1398 },
1399 {
1400 name: "git error",
1401 cmdExitStatus: 1,
1402 cmdStderr: "git error message",
1403 wantCmdArgs: `path/to/git checkout -b trunk --track origin/trunk`,
1404 wantErrorMsg: "failed to run git: git error message",
1405 },
1406 }
1407 for _, tt := range tests {
1408 t.Run(tt.name, func(t *testing.T) {
1409 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
1410 client := Client{
1411 GitPath: "path/to/git",
1412 commandContext: cmdCtx,
1413 }
1414 err := client.CheckoutNewBranch(context.Background(), "origin", "trunk")
1415 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
1416 if tt.wantErrorMsg == "" {
1417 assert.NoError(t, err)
1418 } else {
1419 assert.EqualError(t, err, tt.wantErrorMsg)
1420 }
1421 })
1422 }
1423}
1424
1425func TestClientToplevelDir(t *testing.T) {
1426 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected