Skip to content

Commit

Permalink
add github tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
  • Loading branch information
anubhav06 committed May 6, 2023
1 parent 0a1703d commit 305e4d5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion githubparser/v1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (gh *GitHubURL) GetURL() *url.URL {
}
}
func IsHostGitHub(host string) bool {
return host == githubapi.DEFAULT_HOST || host == githubapi.RAW_HOST
return host == githubapi.DEFAULT_HOST || host == githubapi.RAW_HOST || host == githubapi.SUBDOMAIN_HOST
}

func (gh *GitHubURL) GetProvider() string { return apis.ProviderGitHub.String() }
Expand Down
17 changes: 17 additions & 0 deletions githubparser/v1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
urlD = "https://raw.githubusercontent.com/kubescape/go-git-url/master/files/file0.json"
urlE = "git@github.com:kubescape/go-git-url.git"
urlF = "git@github.com:foobar/kubescape/go-git-url.git"
urlG = "https://www.github.com/kubescape/go-git-url"
)

func TestNewGitHubParserWithURL(t *testing.T) {
Expand Down Expand Up @@ -73,6 +74,16 @@ func TestNewGitHubParserWithURL(t *testing.T) {
_, _ = NewGitHubParserWithURL(urlF)
})
}
{
gh, err := NewGitHubParserWithURL(urlG)
assert.NoError(t, err)
assert.Equal(t, "github.com", gh.GetHostName())
assert.Equal(t, "kubescape", gh.GetOwnerName())
assert.Equal(t, "go-git-url", gh.GetRepoName())
assert.Equal(t, urlA, gh.GetURL().String())
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, "", gh.GetPath())
}
}

func TestSetDefaultBranch(t *testing.T) {
Expand All @@ -94,4 +105,10 @@ func TestSetDefaultBranch(t *testing.T) {
assert.NoError(t, gh.SetDefaultBranchName())
assert.Equal(t, "master", gh.GetBranchName())
}
{
gh, err := NewGitHubParserWithURL(urlG)
assert.NoError(t, err)
assert.NoError(t, gh.SetDefaultBranchName())
assert.Equal(t, "master", gh.GetBranchName())
}
}
10 changes: 10 additions & 0 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ func TestNewGitURL(t *testing.T) {
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, githubURL, gh.GetURL().String())
}
{ // parse github
const githubURL = "https://www.github.com/kubescape/go-git-url"
gh, err := NewGitURL(githubURL)
assert.NoError(t, err)
assert.Equal(t, "github", gh.GetProvider())
assert.Equal(t, "kubescape", gh.GetOwnerName())
assert.Equal(t, "go-git-url", gh.GetRepoName())
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, "https://github.com/kubescape/go-git-url", gh.GetURL().String())
}
{ // parse github
const githubURL = "git@github.com:kubescape/go-git-url.git"
gh, err := NewGitURL(githubURL)
Expand Down

0 comments on commit 305e4d5

Please sign in to comment.