(t *testing.T)
| 389 | } |
| 390 | |
| 391 | func TestClientConfig(t *testing.T) { |
| 392 | tests := []struct { |
| 393 | name string |
| 394 | cmdExitStatus int |
| 395 | cmdStdout string |
| 396 | cmdStderr string |
| 397 | wantCmdArgs string |
| 398 | wantOut string |
| 399 | wantErrorMsg string |
| 400 | }{ |
| 401 | { |
| 402 | name: "get config key", |
| 403 | cmdStdout: "test", |
| 404 | wantCmdArgs: `path/to/git config credential.helper`, |
| 405 | wantOut: "test", |
| 406 | }, |
| 407 | { |
| 408 | name: "get unknown config key", |
| 409 | cmdExitStatus: 1, |
| 410 | cmdStderr: "git error message", |
| 411 | wantCmdArgs: `path/to/git config credential.helper`, |
| 412 | wantErrorMsg: "failed to run git: unknown config key credential.helper", |
| 413 | }, |
| 414 | { |
| 415 | name: "git error", |
| 416 | cmdExitStatus: 2, |
| 417 | cmdStderr: "git error message", |
| 418 | wantCmdArgs: `path/to/git config credential.helper`, |
| 419 | wantErrorMsg: "failed to run git: git error message", |
| 420 | }, |
| 421 | } |
| 422 | for _, tt := range tests { |
| 423 | t.Run(tt.name, func(t *testing.T) { |
| 424 | cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr) |
| 425 | client := Client{ |
| 426 | GitPath: "path/to/git", |
| 427 | commandContext: cmdCtx, |
| 428 | } |
| 429 | out, err := client.Config(context.Background(), "credential.helper") |
| 430 | assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " ")) |
| 431 | if tt.wantErrorMsg == "" { |
| 432 | assert.NoError(t, err) |
| 433 | } else { |
| 434 | assert.EqualError(t, err, tt.wantErrorMsg) |
| 435 | } |
| 436 | assert.Equal(t, tt.wantOut, out) |
| 437 | }) |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | func TestClientUncommittedChangeCount(t *testing.T) { |
| 442 | tests := []struct { |
nothing calls this directly
no test coverage detected