X Tutup
package git import ( "reflect" "testing" ) // TODO: extract assertion helpers into a shared package func eq(t *testing.T, got interface{}, expected interface{}) { t.Helper() if !reflect.DeepEqual(got, expected) { t.Errorf("expected: %v, got: %v", expected, got) } } func Test_parseRemotes(t *testing.T) { remoteList := []string{ "mona\tgit@github.com:monalisa/myfork.git (fetch)", "origin\thttps://github.com/monalisa/octo-cat.git (fetch)", "origin\thttps://github.com/monalisa/octo-cat-push.git (push)", "upstream\thttps://example.com/nowhere.git (fetch)", "upstream\thttps://github.com/hubot/tools (push)", "zardoz\thttps://example.com/zed.git (push)", } r := parseRemotes(remoteList) eq(t, len(r), 4) eq(t, r[0].Name, "mona") eq(t, r[0].FetchURL.String(), "ssh://git@github.com/monalisa/myfork.git") if r[0].PushURL != nil { t.Errorf("expected no PushURL, got %q", r[0].PushURL) } eq(t, r[1].Name, "origin") eq(t, r[1].FetchURL.Path, "/monalisa/octo-cat.git") eq(t, r[1].PushURL.Path, "/monalisa/octo-cat-push.git") eq(t, r[2].Name, "upstream") eq(t, r[2].FetchURL.Host, "example.com") eq(t, r[2].PushURL.Host, "github.com") eq(t, r[3].Name, "zardoz") }
X Tutup