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

Function TestClientCheckoutBranch

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

Source from the content-addressed store, hash-verified

1349}
1350
1351func TestClientCheckoutBranch(t *testing.T) {
1352 tests := []struct {
1353 name string
1354 cmdExitStatus int
1355 cmdStdout string
1356 cmdStderr string
1357 wantCmdArgs string
1358 wantErrorMsg string
1359 }{
1360 {
1361 name: "checkout branch",
1362 wantCmdArgs: `path/to/git checkout trunk`,
1363 },
1364 {
1365 name: "git error",
1366 cmdExitStatus: 1,
1367 cmdStderr: "git error message",
1368 wantCmdArgs: `path/to/git checkout trunk`,
1369 wantErrorMsg: "failed to run git: git error message",
1370 },
1371 }
1372 for _, tt := range tests {
1373 t.Run(tt.name, func(t *testing.T) {
1374 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
1375 client := Client{
1376 GitPath: "path/to/git",
1377 commandContext: cmdCtx,
1378 }
1379 err := client.CheckoutBranch(context.Background(), "trunk")
1380 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
1381 if tt.wantErrorMsg == "" {
1382 assert.NoError(t, err)
1383 } else {
1384 assert.EqualError(t, err, tt.wantErrorMsg)
1385 }
1386 })
1387 }
1388}
1389
1390func TestClientCheckoutNewBranch(t *testing.T) {
1391 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected