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

Function TestRemoteTrackingRef

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

Source from the content-addressed store, hash-verified

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