- Per ssh_config(5), keywords and arguments may be separated by an `=` sign as well as whitespace. - When following the `Include` directive, skip directories that were returned as the result of globbing. - Respect the `Host` context when recursing into `Include`s - Avoid having tests read from the actual filesystem. - Avoid repeatedly looking up the home directory.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
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")
|
|
}
|