MCPcopy
hub / github.com/cli/cli / TestClientCheckoutBranch

Function TestClientCheckoutBranch

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

Source from the content-addressed store, hash-verified

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