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

Function TestClientDeleteLocalBranch

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

Source from the content-addressed store, hash-verified

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