Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package repo
import (
"testing"
)
func BenchmarkIsRemote(b *testing.B) {
repos := []Repo{
{Path: "git://github.com/foo/far"},
{Path: "git://github.com/foo/far.git"},
{Path: "git@github.com:foo/far"},
{Path: "git@github.com:foo/far.git"},
{Path: "http://github.com/foo/far.git"},
{Path: "https://github.com/foo/far.git"},
{Path: "ssh://baz.com/foo/far.git"},
{Path: "/var/lib/src"},
{Path: "/home/ubuntu/src"},
{Path: "src"},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, r := range repos {
r.IsRemote()
}
}
}
func BenchmarkIsRemoteRegex(b *testing.B) {
repos := []Repo{
{Path: "git://github.com/foo/far"},
{Path: "git://github.com/foo/far.git"},
{Path: "git@github.com:foo/far"},
{Path: "git@github.com:foo/far.git"},
{Path: "http://github.com/foo/far.git"},
{Path: "https://github.com/foo/far.git"},
{Path: "ssh://baz.com/foo/far.git"},
{Path: "/var/lib/src"},
{Path: "/home/ubuntu/src"},
{Path: "src"},
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, r := range repos {
r.IsRemoteRegex()
}
}
}
func TestIsRemote(t *testing.T) {
repos := []struct {
path string
remote bool
}{
{"git://github.com/foo/far", true},
{"git://github.com/foo/far.git", true},
{"git@github.com:foo/far", true},
{"git@github.com:foo/far.git", true},
{"http://github.com/foo/far.git", true},
{"https://github.com/foo/far.git", true},
{"ssh://baz.com/foo/far.git", true},
{"/var/lib/src", false},
{"/home/ubuntu/src", false},
{"src", false},
}
for _, r := range repos {
repo := Repo{Path: r.path}
if remote := repo.IsRemote(); remote != r.remote {
t.Errorf("IsRemote %s was %v, expected %v", r.path, remote, r.remote)
}
}
}
func TestIsRemoteRegex(t *testing.T) {
repos := []struct {
path string
remote bool
}{
{"git://github.com/foo/far", true},
{"git://github.com/foo/far.git", true},
{"git@github.com:foo/far", true},
{"git@github.com:foo/far.git", true},
{"http://github.com/foo/far.git", true},
{"https://github.com/foo/far.git", true},
{"ssh://baz.com/foo/far.git", true},
{"/var/lib/src", false},
{"/home/ubuntu/src", false},
{"src", false},
}
for _, r := range repos {
repo := Repo{Path: r.path}
if remote := repo.IsRemoteRegex(); remote != r.remote {
t.Errorf("IsRemote %s was %v, expected %v", r.path, remote, r.remote)
}
}
}
func TestIsGit(t *testing.T) {
repos := []struct {
path string
remote bool
}{
{"git://github.com/foo/far", true},
{"git://github.com/foo/far.git", true},
{"git@github.com:foo/far", true},
{"git@github.com:foo/far.git", true},
{"http://github.com/foo/far.git", true},
{"https://github.com/foo/far.git", true},
{"ssh://baz.com/foo/far.git", true},
{"svn://gcc.gnu.org/svn/gcc/branches/gccgo", false},
{"https://code.google.com/p/go", false},
}
for _, r := range repos {
repo := Repo{Path: r.path}
if remote := repo.IsGit(); remote != r.remote {
t.Errorf("IsGit %s was %v, expected %v", r.path, remote, r.remote)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.