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