-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unittest to cover gitlab CR regex (#3102)
Add different test cases to cover regex defined in 'GitLabCodeRepository' 'check_remote_url' method. Signed-off-by: Tigran Grigoryan <grigoryan.tigran119@gmail.com>
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
88 changes: 88 additions & 0 deletions
88
tests/integration/integrations/gitlab/code_repositories/test_gitlab_code_repository.py
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, Dict | ||
|
||
import pytest | ||
|
||
from zenml.integrations.gitlab.code_repositories.gitlab_code_repository import ( | ||
GitLabCodeRepository, | ||
) | ||
|
||
CONFIG_I = { | ||
"url": "https://gitlab.com", | ||
"host": "gitlab.com", | ||
"group": "example", | ||
"project": "test", | ||
} | ||
|
||
CONFIG_II = { | ||
"url": "https://private-gitlab.example.com", | ||
"host": "private-gitlab.example.com", | ||
"group": "example", | ||
"project": "test", | ||
} | ||
|
||
|
||
@dataclass | ||
class DummyGitLabCodeRepositoryConfig: | ||
url: str | ||
group: str | ||
project: str | ||
host: str | ||
|
||
|
||
class DummyGitLabCodeRepository(GitLabCodeRepository): | ||
def __init__(self, config: Dict[str, Any]) -> None: | ||
self._config = config | ||
|
||
@property | ||
def config(self) -> DummyGitLabCodeRepositoryConfig: | ||
return DummyGitLabCodeRepositoryConfig(**self._config) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("config", "url", "expected"), | ||
[ | ||
(CONFIG_I, "git@gitlab.com:example/test.git", True), | ||
(CONFIG_I, "git@gitlab.com:/example/test.git", True), | ||
(CONFIG_I, "ssh://git@gitlab.com:example/test.git", False), | ||
(CONFIG_I, "ssh://git@gitlab.com:/example/test.git", True), | ||
(CONFIG_I, "ssh://git@gitlab.com:22/example/test.git", True), | ||
( | ||
CONFIG_II, | ||
"ssh://git@private-gitlab.example.com:2222/example/test.git", | ||
True, | ||
), | ||
( | ||
CONFIG_II, | ||
"https://private-gitlab.example.com/example/test.git", | ||
True, | ||
), | ||
( | ||
CONFIG_II, | ||
"https://private-gitlab.example.invalid/example/test.git", | ||
False, | ||
), | ||
( | ||
CONFIG_II, | ||
"https://private-gitlab.example.com/invalid/test.git", | ||
False, | ||
), | ||
( | ||
CONFIG_II, | ||
"https://private-gitlab.example.com/example/invalid.git", | ||
False, | ||
), | ||
( | ||
CONFIG_II, | ||
"https://private-gitlab.example.com/example/test.invalid", | ||
False, | ||
), | ||
], | ||
) | ||
def test_check_remote_url( | ||
config: Dict[str, Any], | ||
url: str, | ||
expected: Any, | ||
) -> None: | ||
cr = DummyGitLabCodeRepository(config) | ||
assert cr.check_remote_url(url) == expected |