-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for browsing github repositories on sourcegraph
- Loading branch information
Showing
1 changed file
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,77 @@ | |
import pathlib | ||
import unittest | ||
|
||
from git_browse import sourcegraph, phabricator, typedefs | ||
from git_browse import github, sourcegraph, phabricator, typedefs | ||
|
||
BASE_DIRECTORY = pathlib.Path(__file__).parents[2] | ||
|
||
|
||
class SourcegraphHost(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.obj = sourcegraph.SourcegraphHost( | ||
typedefs.GitConfig("", "master"), | ||
"github.com", | ||
"albertyw/git-browse", | ||
) | ||
self.uber_obj = sourcegraph.SourcegraphHost( | ||
typedefs.GitConfig("", "master"), | ||
"code.uber.internal", | ||
"asdf/qwer", | ||
) | ||
self.uber_obj.host_class = phabricator.PhabricatorHost | ||
|
||
def test_init(self) -> None: | ||
self.assertEqual(self.obj.host, "github.com") | ||
self.assertEqual(self.obj.repository, "albertyw/git-browse") | ||
|
||
def test_create(self) -> None: | ||
repo = "[email protected]:a/b" | ||
git_config = typedefs.GitConfig(repo, "master") | ||
git_config.try_url_match(github.GITHUB_SSH_URL) | ||
obj = sourcegraph.SourcegraphHost.create(git_config) | ||
self.assertEqual(obj.repository, "a/b") | ||
|
||
def test_create_dot_git(self) -> None: | ||
repo = "[email protected]:a/b.git" | ||
git_config = typedefs.GitConfig(repo, "master") | ||
git_config.try_url_match(github.GITHUB_SSH_URL) | ||
obj = sourcegraph.SourcegraphHost.create(git_config) | ||
self.assertEqual(obj.repository, "a/b") | ||
|
||
def test_get_url_commit(self) -> None: | ||
git_object = typedefs.FocusHash("abcd") | ||
url = self.obj.get_url(git_object) | ||
self.assertEqual( | ||
url, | ||
sourcegraph.PUBLIC_SOURCEGRAPH_URL | ||
+ "github.com/albertyw/git-browse/-/commit/abcd", | ||
) | ||
|
||
def test_get_url_root(self) -> None: | ||
git_object = typedefs.FocusObject(os.sep) | ||
url = self.obj.get_url(git_object) | ||
self.assertEqual( | ||
url, sourcegraph.PUBLIC_SOURCEGRAPH_URL + "github.com/albertyw/git-browse" | ||
) | ||
|
||
def test_get_url_directory(self) -> None: | ||
git_object = typedefs.FocusObject("git_browse" + os.sep) | ||
url = self.obj.get_url(git_object) | ||
self.assertEqual( | ||
url, | ||
sourcegraph.PUBLIC_SOURCEGRAPH_URL | ||
+ "github.com/albertyw/git-browse/-/tree/git_browse/", | ||
) | ||
|
||
def test_get_url_file(self) -> None: | ||
git_object = typedefs.FocusObject("README.md") | ||
url = self.obj.get_url(git_object) | ||
self.assertEqual( | ||
url, | ||
sourcegraph.PUBLIC_SOURCEGRAPH_URL | ||
+ "github.com/albertyw/git-browse/-/blob/README.md", | ||
) | ||
|
||
def test_uber_init(self) -> None: | ||
self.assertEqual(self.uber_obj.host, "code.uber.internal") | ||
self.assertEqual(self.uber_obj.repository, "asdf/qwer") | ||
|