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

Function TestClientDeleteLocalBranch

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

Source from the content-addressed store, hash-verified

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