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