forked from attiasr/k8s-operator-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from edwardtheharris/15-try-to-increase-test-c…
…overage 15 try to increase test coverage Closes #15
- Loading branch information
Showing
12 changed files
with
286 additions
and
64 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 +1,16 @@ | ||
"""Kubernetes Agent module.""" | ||
from pathlib import Path | ||
|
||
import version_query | ||
|
||
def get_version(): | ||
"""Query the current version for the project.""" | ||
try: | ||
repo_path = Path(".").resolve() | ||
ret_value = version_query.git_query.query_git_repo(repo_path).to_str() | ||
except ValueError: | ||
ret_value = version_query.Version.from_str('0.0.0') | ||
ret_value = ret_value.devel_increment() | ||
return ret_value | ||
|
||
__version__ = get_version() |
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
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 +1,11 @@ | ||
sonar.coverage.exclusions=tests/ | ||
sonar.organization=edwardtheharris | ||
sonar.projectKey=edwardtheharris_k8s-operator-agent | ||
sonar.projectName=k8s-operator-agent | ||
sonar.projectVersion=__version__ | ||
sonar.python.coverage.reportPaths=coverage.xml | ||
sonar.python.pylint.reportPaths=pylint.yml | ||
sonar.python.version=3.8,3.9,3.10,3.11,3.12 | ||
sonar.sourceEncoding=UTF-8 | ||
sonar.sources=k8s_agent/ | ||
sonar.tests=tests/ |
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,49 @@ | ||
"""Kubernetes Operator Agent init test module.""" | ||
# pylint: disable=redefined-outer-name,reimported,import-outside-toplevel | ||
from unittest.mock import patch | ||
from unittest.mock import MagicMock | ||
|
||
import version_query | ||
|
||
from k8s_agent import get_version | ||
from k8s_agent import __version__ | ||
|
||
def test_get_version_success(): | ||
"""Test get_version when git version query is successful. | ||
Mock the return value of query_git_repo to simulate successful | ||
version retrieval. | ||
""" | ||
|
||
mock_version = MagicMock() | ||
mock_version.to_str.return_value = "1.2.3" | ||
|
||
with patch("k8s_agent.version_query.git_query.query_git_repo", | ||
return_value=mock_version): | ||
version = get_version() | ||
assert version == "1.2.3" | ||
mock_version.to_str.assert_called_once() | ||
|
||
def test_get_version_fallback(): | ||
"""Test get_version failure back to default version. | ||
Mock the query_git_repo to raise a ValueError | ||
Mock the Version.from_str and its devel_increment behavior | ||
""" | ||
with patch("k8s_agent.version_query.git_query.query_git_repo", | ||
side_effect=ValueError): | ||
mock_version = MagicMock() | ||
mock_version.devel_increment.return_value = "0.0.1" | ||
|
||
with patch("k8s_agent.version_query.Version.from_str", | ||
return_value=mock_version): | ||
version = get_version() | ||
assert version == "0.0.1" | ||
mock_version.devel_increment.assert_called_once() | ||
|
||
def test_version_init(): | ||
"""Test if __version__ is initialized correctly.""" | ||
with patch("k8s_agent.get_version", return_value="1.2.3"): | ||
from k8s_agent import __version__ | ||
assert __version__ == version_query.Version.from_str("0.0.1.dev1") |