MCPcopy
hub / github.com/cli/cli / TestClientDeleteLocalBranch

Function TestClientDeleteLocalBranch

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

Source from the content-addressed store, hash-verified

1271}
1272
1273func TestClientDeleteLocalBranch(t *testing.T) {
1274 tests := []struct {
1275 name string
1276 cmdExitStatus int
1277 cmdStdout string
1278 cmdStderr string
1279 wantCmdArgs string
1280 wantErrorMsg string
1281 }{
1282 {
1283 name: "delete local branch",
1284 wantCmdArgs: `path/to/git branch -D trunk`,
1285 },
1286 {
1287 name: "git error",
1288 cmdExitStatus: 1,
1289 cmdStderr: "git error message",
1290 wantCmdArgs: `path/to/git branch -D trunk`,
1291 wantErrorMsg: "failed to run git: git error message",
1292 },
1293 }
1294 for _, tt := range tests {
1295 t.Run(tt.name, func(t *testing.T) {
1296 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
1297 client := Client{
1298 GitPath: "path/to/git",
1299 commandContext: cmdCtx,
1300 }
1301 err := client.DeleteLocalBranch(context.Background(), "trunk")
1302 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
1303 if tt.wantErrorMsg == "" {
1304 assert.NoError(t, err)
1305 } else {
1306 assert.EqualError(t, err, tt.wantErrorMsg)
1307 }
1308 })
1309 }
1310}
1311
1312func TestClientHasLocalBranch(t *testing.T) {
1313 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected