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

Function TestClientParsePushRevision

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

Source from the content-addressed store, hash-verified

1077}
1078
1079func TestClientParsePushRevision(t *testing.T) {
1080 tests := []struct {
1081 name string
1082 branch string
1083 commandResult commandResult
1084 wantParsedPushRevision RemoteTrackingRef
1085 wantError error
1086 }{
1087 {
1088 name: "@{push} resolves to refs/remotes/origin/branchName",
1089 branch: "branchName",
1090 commandResult: commandResult{
1091 ExitStatus: 0,
1092 Stdout: "refs/remotes/origin/branchName",
1093 },
1094 wantParsedPushRevision: RemoteTrackingRef{Remote: "origin", Branch: "branchName"},
1095 },
1096 {
1097 name: "@{push} doesn't resolve",
1098 commandResult: commandResult{
1099 ExitStatus: 128,
1100 Stderr: "fatal: git error",
1101 },
1102 wantParsedPushRevision: RemoteTrackingRef{},
1103 wantError: &GitError{
1104 ExitCode: 128,
1105 Stderr: "fatal: git error",
1106 },
1107 },
1108 {
1109 name: "@{push} resolves to something surprising",
1110 commandResult: commandResult{
1111 ExitStatus: 0,
1112 Stdout: "not/a/valid/remote/ref",
1113 },
1114 wantParsedPushRevision: RemoteTrackingRef{},
1115 wantError: fmt.Errorf("could not parse push revision: remote tracking branch must have format refs/remotes/<remote>/<branch> but was: not/a/valid/remote/ref"),
1116 },
1117 }
1118 for _, tt := range tests {
1119 t.Run(tt.name, func(t *testing.T) {
1120 cmd := fmt.Sprintf("path/to/git rev-parse --symbolic-full-name %s@{push}", tt.branch)
1121 cmdCtx := createMockedCommandContext(t, mockedCommands{
1122 args(cmd): tt.commandResult,
1123 })
1124 client := Client{
1125 GitPath: "path/to/git",
1126 commandContext: cmdCtx,
1127 }
1128 trackingRef, err := client.PushRevision(context.Background(), tt.branch)
1129 if tt.wantError != nil {
1130 var wantErrorAsGit *GitError
1131 if errors.As(err, &wantErrorAsGit) {
1132 var gitError *GitError
1133 require.ErrorAs(t, err, &gitError)
1134 assert.Equal(t, wantErrorAsGit.ExitCode, gitError.ExitCode)
1135 assert.Equal(t, wantErrorAsGit.Stderr, gitError.Stderr)
1136 } else {

Callers

nothing calls this directly

Calls 6

PushRevisionMethod · 0.95
EqualMethod · 0.80
argsTypeAlias · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected