Skip to content

Commit

Permalink
Add unittest to cover gitlab CR regex (#3102)
Browse files Browse the repository at this point in the history
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
4gt-104 authored Oct 21, 2024
1 parent 0130823 commit 30f1765
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Empty file.
Empty file.
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

0 comments on commit 30f1765

Please sign in to comment.