Created
February 21, 2014 21:10
-
-
Save aodin/9143598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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