(t *testing.T)
| 949 | } |
| 950 | |
| 951 | func TestClientPushDefault(t *testing.T) { |
| 952 | tests := []struct { |
| 953 | name string |
| 954 | commandResult commandResult |
| 955 | wantPushDefault PushDefault |
| 956 | wantError *GitError |
| 957 | }{ |
| 958 | { |
| 959 | name: "push default is not set", |
| 960 | commandResult: commandResult{ |
| 961 | ExitStatus: 1, |
| 962 | Stderr: "error: key does not contain a section: remote.pushDefault", |
| 963 | }, |
| 964 | wantPushDefault: PushDefaultSimple, |
| 965 | wantError: nil, |
| 966 | }, |
| 967 | { |
| 968 | name: "push default is set to current", |
| 969 | commandResult: commandResult{ |
| 970 | ExitStatus: 0, |
| 971 | Stdout: "current", |
| 972 | }, |
| 973 | wantPushDefault: PushDefaultCurrent, |
| 974 | wantError: nil, |
| 975 | }, |
| 976 | { |
| 977 | name: "push default errors", |
| 978 | commandResult: commandResult{ |
| 979 | ExitStatus: 128, |
| 980 | Stderr: "fatal: git error", |
| 981 | }, |
| 982 | wantPushDefault: "", |
| 983 | wantError: &GitError{ |
| 984 | ExitCode: 128, |
| 985 | Stderr: "fatal: git error", |
| 986 | }, |
| 987 | }, |
| 988 | } |
| 989 | for _, tt := range tests { |
| 990 | t.Run(tt.name, func(t *testing.T) { |
| 991 | cmdCtx := createMockedCommandContext(t, mockedCommands{ |
| 992 | `path/to/git config push.default`: tt.commandResult, |
| 993 | }, |
| 994 | ) |
| 995 | client := Client{ |
| 996 | GitPath: "path/to/git", |
| 997 | commandContext: cmdCtx, |
| 998 | } |
| 999 | pushDefault, err := client.PushDefault(context.Background()) |
| 1000 | if tt.wantError != nil { |
| 1001 | var gitError *GitError |
| 1002 | require.ErrorAs(t, err, &gitError) |
| 1003 | assert.Equal(t, tt.wantError.ExitCode, gitError.ExitCode) |
| 1004 | assert.Equal(t, tt.wantError.Stderr, gitError.Stderr) |
| 1005 | } else { |
| 1006 | require.NoError(t, err) |
| 1007 | } |
| 1008 | assert.Equal(t, tt.wantPushDefault, pushDefault) |
nothing calls this directly
no test coverage detected