MCPcopy
hub / github.com/cli/cli / TestClientParsePushRevision

Function TestClientParsePushRevision

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

Source from the content-addressed store, hash-verified

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