-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* table test for all RepoPieces results * use both regex and uri parse for remotes * bump version to 0.10.7
- Loading branch information
Showing
3 changed files
with
156 additions
and
83 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,119 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/gSchool/glearn-cli/api/learn" | ||
"testing" | ||
) | ||
|
||
func Test_parseHostedGitRegex_many(t *testing.T) { | ||
var origins = []string{ | ||
"[email protected]:gsei19/nineteen-week/week-02-full-stack-by-feature.git", | ||
"https://gitlab.com/gsei19/week-05.git", | ||
"[email protected]:golang/from/go.git", | ||
"ssh://[email protected]/path/to/repo.git/", | ||
"ssh://[email protected]:1234/path-path/to-to/repo-repo.git/", | ||
"ssh://host.xz:7634/path/to/repo-name-nam.git/", | ||
"ssh://host.xz/path/to/repo-name.git/", | ||
"ssh://[email protected]/path/to/repo-name.git/", | ||
"ssh://host.xz/path/to/repo-name.git/", | ||
"[email protected]:/path/to/repo.git/", | ||
"host.xz:/path/to/repo-name.git/", | ||
"[email protected]:path/to/repo.git", | ||
"host.xz:path/to/repo.git", | ||
"rsync://host.xz/path/to/repo.git/", | ||
"git://host.xz/path/to/repo.git/", | ||
"http://host.xz/path/to/repo.git/", | ||
"https://host.xz/path/to/repo.git/", | ||
func Test_parseHostedGit_many(t *testing.T) { | ||
type urlToRepo struct { | ||
url string | ||
result learn.RepoPieces | ||
} | ||
for _, origin := range origins { | ||
var repoPieces, _ = parseHostedGitRegex(origin) | ||
if repoPieces.Org == "" { | ||
t.Errorf("Org parse failed") | ||
} | ||
} | ||
} | ||
|
||
func Test_parseRepoPieces_TopLevelOrg(t *testing.T) { | ||
repoPieces, err := parseHostedGitRegex("https://gitlab.com/gsei19/week-05.git") | ||
|
||
if err != nil { | ||
t.Errorf("Threw an error") | ||
} | ||
|
||
// https://gitlab.com/gsei19/nineteen-week/week-05.git | ||
|
||
if repoPieces.Org != "gsei19" { | ||
t.Errorf("Incorrect org parse") | ||
} | ||
} | ||
|
||
func Test_parseRepoPieces_TopLevelOrg_Ssh(t *testing.T) { | ||
repoPieces, err := parseHostedGitRegex("[email protected]:golang/go.git") | ||
|
||
if err != nil { | ||
t.Errorf("Threw an error") | ||
} | ||
|
||
// https://gitlab.com/gsei19/nineteen-week/week-05.git | ||
|
||
if repoPieces.Origin != "github.com" { | ||
t.Errorf("Incorrect Origin parse") | ||
} | ||
|
||
if repoPieces.RepoName != "go" { | ||
t.Errorf("Incorrect RepoName parse") | ||
} | ||
|
||
if repoPieces.Org != "golang" { | ||
t.Errorf("Incorrect org parse") | ||
} | ||
} | ||
|
||
func Test_parseRepoPieces_NestedOrg(t *testing.T) { | ||
repoPieces, err := parseHostedGitRegex("https://gitlab.com/gsei19/nineteen-week/week-05.git") | ||
|
||
if err != nil { | ||
t.Errorf("Threw an error") | ||
var origins = []urlToRepo{ | ||
{ | ||
url: "[email protected]:gsei19/nineteen-week/week-02-full-stack-by-feature.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "gsei19", RepoName: "nineteen-week/week-02-full-stack-by-feature"}, | ||
}, | ||
{ | ||
url: "https://gitlab.com/gsei19/week-05.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "gsei19", RepoName: "week-05"}, | ||
}, | ||
{ | ||
url: "https://gitlab.com/gsei19/week-05.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "gsei19", RepoName: "week-05"}, | ||
}, | ||
{ | ||
url: "[email protected]:golang/from/go.git", | ||
result: learn.RepoPieces{Origin: "github.com", Org: "golang", RepoName: "from/go"}, | ||
}, | ||
{ | ||
url: "ssh://[email protected]/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "ssh://[email protected]:1234/path-path/to-to/repo-repo.git/", | ||
result: learn.RepoPieces{Origin: "host-website.xz", Org: "path-path", RepoName: "to-to/repo-repo"}, | ||
}, | ||
{ | ||
url: "ssh://host.xz:7634/path/to/repo-name-nam.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo-name-nam"}, | ||
}, | ||
{ | ||
url: "ssh://host.xz/path/to/repo-name.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo-name"}, | ||
}, | ||
{ | ||
url: "ssh://[email protected]/path/to/repo-name.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo-name"}, | ||
}, | ||
{ | ||
url: "ssh://host.xz/path/to/repo-name.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo-name"}, | ||
}, | ||
{ | ||
url: "[email protected]:/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "host.xz:/path/to/repo-name.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo-name"}, | ||
}, | ||
{ | ||
url: "[email protected]:path/to/repo.git", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "host.xz:path/to/repo.git", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "rsync://host.xz/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "git://host.xz/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "http://host.xz/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "https://host.xz/path/to/repo.git/", | ||
result: learn.RepoPieces{Origin: "host.xz", Org: "path", RepoName: "to/repo"}, | ||
}, | ||
{ | ||
url: "https://oauth2:[email protected]/galvanize-labs/curriculum-development/agile.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "galvanize-labs", RepoName: "curriculum-development/agile"}, | ||
}, | ||
{ | ||
url: "https://[email protected]/galvanize-labs/curriculum-development/spring/spring-web.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "galvanize-labs", RepoName: "curriculum-development/spring/spring-web"}, | ||
}, | ||
{ | ||
url: "ssh://[email protected]/galvanize-labs/curriculum-development/application-architectures/12-factor-app/00-introduction.git", | ||
result: learn.RepoPieces{Origin: "gitlab.com", Org: "galvanize-labs", RepoName: "curriculum-development/application-architectures/12-factor-app/00-introduction"}, | ||
}, | ||
} | ||
|
||
// https://gitlab.com/gsei19/nineteen-week/week-05.git | ||
|
||
if repoPieces.Org != "gsei19/nineteen-week" { | ||
t.Errorf("Incorrect org parse") | ||
for _, expected := range origins { | ||
var test, err = parseHostedGit(expected.url) | ||
if err != nil { | ||
t.Errorf("given %s returned error: %s\n", expected.url, err) | ||
return | ||
} | ||
if test.Org != expected.result.Org { | ||
t.Errorf("Org parse failed!\ngiven: %s\n expect: %s\n result: %s\n", expected.url, expected.result.Org, test.Org) | ||
return | ||
} | ||
if test.Origin != expected.result.Origin { | ||
t.Errorf("Origin parse failed!\n given: %s\n expect: %s\n result: %s\n", expected.url, expected.result.Origin, test.Origin) | ||
return | ||
} | ||
if test.RepoName != expected.result.RepoName { | ||
t.Errorf("RepoName parse failed!\n given: %s\n expect: %s\n result: %s\n", expected.url, expected.result.RepoName, test.RepoName) | ||
return | ||
} | ||
} | ||
} |
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