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

Function TestClientRemotePushDefault

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

Source from the content-addressed store, hash-verified

1015}
1016
1017func TestClientRemotePushDefault(t *testing.T) {
1018 tests := []struct {
1019 name string
1020 commandResult commandResult
1021 wantRemotePushDefault string
1022 wantError *GitError
1023 }{
1024 {
1025 name: "remote.pushDefault is not set",
1026 commandResult: commandResult{
1027 ExitStatus: 1,
1028 Stderr: "error: key does not contain a section: remote.pushDefault",
1029 },
1030 wantRemotePushDefault: "",
1031 wantError: nil,
1032 },
1033 {
1034 name: "remote.pushDefault is set to origin",
1035 commandResult: commandResult{
1036 ExitStatus: 0,
1037 Stdout: "origin",
1038 },
1039 wantRemotePushDefault: "origin",
1040 wantError: nil,
1041 },
1042 {
1043 name: "remote.pushDefault errors",
1044 commandResult: commandResult{
1045 ExitStatus: 128,
1046 Stderr: "fatal: git error",
1047 },
1048 wantRemotePushDefault: "",
1049 wantError: &GitError{
1050 ExitCode: 128,
1051 Stderr: "fatal: git error",
1052 },
1053 },
1054 }
1055 for _, tt := range tests {
1056 t.Run(tt.name, func(t *testing.T) {
1057 cmdCtx := createMockedCommandContext(t, mockedCommands{
1058 `path/to/git config remote.pushDefault`: tt.commandResult,
1059 },
1060 )
1061 client := Client{
1062 GitPath: "path/to/git",
1063 commandContext: cmdCtx,
1064 }
1065 pushDefault, err := client.RemotePushDefault(context.Background())
1066 if tt.wantError != nil {
1067 var gitError *GitError
1068 require.ErrorAs(t, err, &gitError)
1069 assert.Equal(t, tt.wantError.ExitCode, gitError.ExitCode)
1070 assert.Equal(t, tt.wantError.Stderr, gitError.Stderr)
1071 } else {
1072 require.NoError(t, err)
1073 }
1074 assert.Equal(t, tt.wantRemotePushDefault, pushDefault)

Callers

nothing calls this directly

Calls 4

RemotePushDefaultMethod · 0.95
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected