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

Function TestRemoteTrackingRef

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

Source from the content-addressed store, hash-verified

1145}
1146
1147func TestRemoteTrackingRef(t *testing.T) {
1148 t.Run("parsing", func(t *testing.T) {
1149 t.Parallel()
1150
1151 tests := []struct {
1152 name string
1153 remoteTrackingRef string
1154 wantRemoteTrackingRef RemoteTrackingRef
1155 wantError error
1156 }{
1157 {
1158 name: "valid remote tracking ref without slash in branch name",
1159 remoteTrackingRef: "refs/remotes/origin/branchName",
1160 wantRemoteTrackingRef: RemoteTrackingRef{
1161 Remote: "origin",
1162 Branch: "branchName",
1163 },
1164 },
1165 {
1166 name: "valid remote tracking ref with slash in branch name",
1167 remoteTrackingRef: "refs/remotes/origin/branch/name",
1168 wantRemoteTrackingRef: RemoteTrackingRef{
1169 Remote: "origin",
1170 Branch: "branch/name",
1171 },
1172 },
1173 // TODO: Uncomment when we support slashes in remote names
1174 // {
1175 // name: "valid remote tracking ref with slash in remote name",
1176 // remoteTrackingRef: "refs/remotes/my/origin/branchName",
1177 // wantRemoteTrackingRef: RemoteTrackingRef{
1178 // Remote: "my/origin",
1179 // Branch: "branchName",
1180 // },
1181 // },
1182 // {
1183 // name: "valid remote tracking ref with slash in remote name and branch name",
1184 // remoteTrackingRef: "refs/remotes/my/origin/branch/name",
1185 // wantRemoteTrackingRef: RemoteTrackingRef{
1186 // Remote: "my/origin",
1187 // Branch: "branch/name",
1188 // },
1189 // },
1190 {
1191 name: "incorrect parts",
1192 remoteTrackingRef: "refs/remotes/origin",
1193 wantRemoteTrackingRef: RemoteTrackingRef{},
1194 wantError: fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: refs/remotes/origin"),
1195 },
1196 {
1197 name: "incorrect prefix type",
1198 remoteTrackingRef: "invalid/remotes/origin/branchName",
1199 wantRemoteTrackingRef: RemoteTrackingRef{},
1200 wantError: fmt.Errorf("remote tracking branch must have format refs/remotes/<remote>/<branch> but was: invalid/remotes/origin/branchName"),
1201 },
1202 {
1203 name: "incorrect ref type",
1204 remoteTrackingRef: "refs/invalid/origin/branchName",

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
ParseRemoteTrackingRefFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected