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

Function TestParseRemotes

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

Source from the content-addressed store, hash-verified

161}
162
163func TestParseRemotes(t *testing.T) {
164 // Given remote output with fetch-only, push-only, paired, and mixed URL forms
165 remoteList := []string{
166 "mona\tgit@github.com:monalisa/myfork.git (fetch)",
167 "origin\thttps://github.com/monalisa/octo-cat.git (fetch)",
168 "origin\thttps://github.com/monalisa/octo-cat-push.git (push)",
169 "upstream\thttps://example.com/nowhere.git (fetch)",
170 "upstream\thttps://github.com/hubot/tools (push)",
171 "zardoz\thttps://example.com/zed.git (push)",
172 "koke\tgit://github.com/koke/grit.git (fetch)",
173 "koke\tgit://github.com/koke/grit.git (push)",
174 }
175
176 // When the output is parsed
177 remotes := parseRemotes(remoteList)
178
179 // Then each URL is associated with its named remote and direction
180 require.Len(t, remotes, 5)
181 assert.Equal(t, "mona", remotes[0].Name)
182 assert.Equal(t, "ssh://git@github.com/monalisa/myfork.git", remotes[0].FetchURL.String())
183 assert.Nil(t, remotes[0].PushURL)
184
185 assert.Equal(t, "origin", remotes[1].Name)
186 assert.Equal(t, "/monalisa/octo-cat.git", remotes[1].FetchURL.Path)
187 assert.Equal(t, "/monalisa/octo-cat-push.git", remotes[1].PushURL.Path)
188
189 assert.Equal(t, "upstream", remotes[2].Name)
190 assert.Equal(t, "example.com", remotes[2].FetchURL.Host)
191 assert.Equal(t, "github.com", remotes[2].PushURL.Host)
192
193 assert.Equal(t, "zardoz", remotes[3].Name)
194 assert.Nil(t, remotes[3].FetchURL)
195 assert.Equal(t, "https://example.com/zed.git", remotes[3].PushURL.String())
196
197 assert.Equal(t, "koke", remotes[4].Name)
198 assert.Equal(t, "/koke/grit.git", remotes[4].FetchURL.Path)
199 assert.Equal(t, "/koke/grit.git", remotes[4].PushURL.Path)
200}
201
202func TestClientUpdateRemoteURLUpdatesConfiguredRemote(t *testing.T) {
203 // Given a repository with a local remote

Callers

nothing calls this directly

Calls 4

parseRemotesFunction · 0.85
EqualMethod · 0.80
LenMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected