-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(tests): Add tests for models * ruff auto-fix * test(terraform_resource): Add to_dict() test. * doc(checkout): Add note and update action example regarding fetch-depth. * feat(action): Add log message when updating pr. * fix(provider_cache): Fix provider cache not working. * fix(markdown_tables): Skip table generate for providers without changes. * fix(pr_update): Fix handling of existing prs * fix(action): Fix searching existing pr. * fix(action): Filter pr in python instead of search over github api. * feat(action): Update pr even when no upgrades where performed. * fix(provider_handler): Switch reference of object. * fix(provider_handler): Fix resource update. * fix(provider_handler): Fix resource replace in cache. * fix(provider_handler): REmove indent.
- Loading branch information
Showing
8 changed files
with
234 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from pathlib import Path | ||
|
||
from infrapatch.core.models.versioned_resource import ResourceStatus, VersionedResource | ||
|
||
|
||
def test_version_management(): | ||
# Create new resource with newer version | ||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="test_file.py") | ||
resource.newest_version = "2.0.0" | ||
|
||
assert resource.status == ResourceStatus.UNPATCHED | ||
assert resource.installed_version_equal_or_newer_than_new_version() is False | ||
|
||
resource.set_patched() | ||
assert resource.status == ResourceStatus.PATCHED | ||
|
||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="test_file.py") | ||
resource.newest_version = "1.0.0" | ||
|
||
assert resource.status == ResourceStatus.UNPATCHED | ||
assert resource.installed_version_equal_or_newer_than_new_version() is True | ||
|
||
|
||
def test_tile_constraint(): | ||
resource = VersionedResource(name="test_resource", current_version="~>1.0.0", _source_file="test_file.py") | ||
resource.newest_version = "~>1.0.1" | ||
assert resource.has_tile_constraint() is True | ||
assert resource.installed_version_equal_or_newer_than_new_version() is True | ||
|
||
resource.newest_version = "~>1.1.0" | ||
assert resource.installed_version_equal_or_newer_than_new_version() is False | ||
|
||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="test_file.py") | ||
assert resource.has_tile_constraint() is False | ||
|
||
resource = VersionedResource(name="test_resource", current_version="~>1.0.0", _source_file="test_file.py") | ||
resource.newest_version = "1.1.0" | ||
assert resource.newest_version == "~>1.1.0" | ||
|
||
|
||
def test_patch_error(): | ||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="test_file.py") | ||
resource.set_patch_error() | ||
assert resource.status == ResourceStatus.PATCH_ERROR | ||
|
||
|
||
def test_path(): | ||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="/var/testdir/test_file.py") | ||
assert resource.source_file == Path("/var/testdir/test_file.py") | ||
|
||
|
||
def test_find(): | ||
findably_resource = VersionedResource(name="test_resource3", current_version="1.0.0", _source_file="test_file3.py") | ||
unfindably_resource = VersionedResource(name="test_resource6", current_version="1.0.0", _source_file="test_file8.py") | ||
resources = [ | ||
VersionedResource(name="test_resource1", current_version="1.0.0", _source_file="test_file1.py"), | ||
VersionedResource(name="test_resource2", current_version="1.0.0", _source_file="test_file2.py"), | ||
VersionedResource(name="test_resource3", current_version="1.0.0", _source_file="test_file3.py"), | ||
VersionedResource(name="test_resource4", current_version="1.0.0", _source_file="test_file4.py"), | ||
VersionedResource(name="test_resource5", current_version="1.0.0", _source_file="test_file5.py"), | ||
] | ||
assert len(findably_resource.find(resources)) == 1 | ||
assert findably_resource.find(resources) == [resources[2]] | ||
assert len(unfindably_resource.find(resources)) == 0 | ||
|
||
|
||
def test_versioned_resource_to_dict(): | ||
resource = VersionedResource(name="test_resource", current_version="1.0.0", _source_file="test_file.py") | ||
expected_dict = {"name": "test_resource", "current_version": "1.0.0", "_source_file": "test_file.py", "_newest_version": None, "_status": ResourceStatus.UNPATCHED} | ||
assert resource.to_dict() == expected_dict |
82 changes: 82 additions & 0 deletions
82
infrapatch/core/models/tests/test_versioned_terraform_resource.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,82 @@ | ||
import pytest | ||
|
||
from infrapatch.core.models.versioned_terraform_resources import TerraformModule, TerraformProvider | ||
|
||
|
||
def test_attributes(): | ||
# test with default registry | ||
module = TerraformModule(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="test/test_module/test_provider") | ||
provider = TerraformProvider(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="test_provider/test_provider") | ||
|
||
assert module.source == "test/test_module/test_provider" | ||
assert module.base_domain is None | ||
assert module.identifier == "test/test_module/test_provider" | ||
|
||
assert provider.source == "test_provider/test_provider" | ||
assert provider.base_domain is None | ||
assert provider.identifier == "test_provider/test_provider" | ||
|
||
# test with custom registry | ||
module = TerraformModule(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="testregistry.ch/test/test_module/test_provider") | ||
provider = TerraformProvider(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="testregistry.ch/test_provider/test_provider") | ||
|
||
assert module.source == "testregistry.ch/test/test_module/test_provider" | ||
assert module.base_domain == "testregistry.ch" | ||
assert module.identifier == "test/test_module/test_provider" | ||
|
||
assert provider.source == "testregistry.ch/test_provider/test_provider" | ||
assert provider.base_domain == "testregistry.ch" | ||
assert provider.identifier == "test_provider/test_provider" | ||
|
||
# test invalid sources | ||
with pytest.raises(Exception): | ||
TerraformModule(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="test/test_module/test_provider/test") | ||
TerraformModule(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="/test_module") | ||
|
||
with pytest.raises(Exception): | ||
TerraformProvider(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="/test_module") | ||
TerraformProvider(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="kfdsjflksdj/kldfsjflsdkj/dkljflsk/test_module") | ||
|
||
|
||
def test_find(): | ||
findably_resource = TerraformModule(name="test_resource3", current_version="1.0.0", _source_file="test_file3.py", _source="test/test_module3/test_provider") | ||
unfindably_resource = TerraformModule(name="test_resource6", current_version="1.0.0", _source_file="test_file8.py", _source="test/test_module3/test_provider") | ||
resources = [ | ||
TerraformModule(name="test_resource1", current_version="1.0.0", _source_file="test_file1.py", _source="test/test_module1/test_provider"), | ||
TerraformModule(name="test_resource2", current_version="1.0.0", _source_file="test_file2.py", _source="test/test_module2/test_provider"), | ||
TerraformModule(name="test_resource3", current_version="1.0.0", _source_file="test_file3.py", _source="test/test_module3/test_provider"), | ||
TerraformModule(name="test_resource4", current_version="1.0.0", _source_file="test_file4.py", _source="test/test_module4/test_provider"), | ||
TerraformModule(name="test_resource5", current_version="1.0.0", _source_file="test_file5.py", _source="test/test_module5/test_provider"), | ||
] | ||
assert len(findably_resource.find(resources)) == 1 | ||
assert findably_resource.find(resources) == [resources[2]] | ||
assert len(unfindably_resource.find(resources)) == 0 | ||
|
||
|
||
def test_to_dict(): | ||
module = TerraformModule(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="test/test_module/test_provider") | ||
provider = TerraformProvider(name="test_resource", current_version="1.0.0", _source_file="test_file.py", _source="test_provider/test_provider") | ||
|
||
module_dict = module.to_dict() | ||
provider_dict = provider.to_dict() | ||
|
||
assert module_dict == { | ||
"name": "test_resource", | ||
"current_version": "1.0.0", | ||
"_newest_version": None, | ||
"_status": "unpatched", | ||
"_source_file": "test_file.py", | ||
"_source": "test/test_module/test_provider", | ||
"_base_domain": None, | ||
"_identifier": "test/test_module/test_provider", | ||
} | ||
assert provider_dict == { | ||
"name": "test_resource", | ||
"current_version": "1.0.0", | ||
"_newest_version": None, | ||
"_status": "unpatched", | ||
"_source_file": "test_file.py", | ||
"_source": "test_provider/test_provider", | ||
"_base_domain": None, | ||
"_identifier": "test_provider/test_provider", | ||
} |
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