-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metadata-service: validate that the dockerImageTag is not decremented (…
- Loading branch information
1 parent
24cf967
commit cc003ed
Showing
8 changed files
with
238 additions
and
13 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "metadata-service" | ||
version = "0.9.0" | ||
version = "0.10.0" | ||
description = "" | ||
authors = ["Ben Church <[email protected]>"] | ||
readme = "README.md" | ||
|
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
30 changes: 30 additions & 0 deletions
30
airbyte-ci/connectors/metadata_service/lib/tests/test_docker_hub.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,30 @@ | ||
# | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
|
||
import warnings | ||
|
||
import pytest | ||
from metadata_service import docker_hub | ||
|
||
|
||
@pytest.fixture | ||
def image_name(): | ||
return "airbyte/source-faker" | ||
|
||
|
||
def test_get_docker_hub_tags_and_digests(image_name): | ||
warnings.warn(f"This test can be flaky as its results depends on the current state of {image_name} dockerhub image.", UserWarning) | ||
tags_and_digests = docker_hub.get_docker_hub_tags_and_digests(image_name) | ||
assert isinstance(tags_and_digests, dict) | ||
assert "latest" in tags_and_digests, "The latest tag is not in the returned dict" | ||
assert "0.1.0" in tags_and_digests, f"The first {image_name} version is not in the returned dict" | ||
assert len(tags_and_digests) > 10, f"Pagination is likely not working as we expect more than 10 version of {image_name} to be released" | ||
|
||
|
||
def test_get_latest_version_on_dockerhub(image_name): | ||
warnings.warn(f"This test can be flaky as its results depends on the current state of {image_name} dockerhub image.", UserWarning) | ||
assert ( | ||
docker_hub.get_latest_version_on_dockerhub(image_name) is not None | ||
), f"No latest version found for {image_name}. We expect one to exist." |
Empty file.
99 changes: 99 additions & 0 deletions
99
airbyte-ci/connectors/metadata_service/lib/tests/test_validators/test_metadata_validators.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,99 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
|
||
import pytest | ||
import requests | ||
import semver | ||
import yaml | ||
from metadata_service.models.generated.ConnectorMetadataDefinitionV0 import ConnectorMetadataDefinitionV0 | ||
from metadata_service.validators import metadata_validator | ||
|
||
|
||
@pytest.fixture | ||
def metadata_definition(): | ||
metadata_file_url = ( | ||
"https://raw.githubusercontent.com/airbytehq/airbyte/master/airbyte-integrations/connectors/source-faker/metadata.yaml" | ||
) | ||
response = requests.get(metadata_file_url) | ||
response.raise_for_status() | ||
|
||
metadata_yaml_dict = yaml.safe_load(response.text) | ||
return ConnectorMetadataDefinitionV0.parse_obj(metadata_yaml_dict) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"latest_version, current_version,should_pass_validation", | ||
[("1.0.0", "0.1.0", False), ("1.0.0", "1.0.0", True), ("1.0.0", "1.1.0", True)], | ||
) | ||
def test_validate_docker_image_tag_is_not_decremented(mocker, metadata_definition, latest_version, current_version, should_pass_validation): | ||
mocker.patch.object(metadata_validator, "get_latest_version_on_dockerhub", return_value=latest_version) | ||
metadata_definition.data.dockerImageTag = current_version | ||
passed_validation, _ = metadata_validator.validate_docker_image_tag_is_not_decremented(metadata_definition, None) | ||
assert passed_validation == should_pass_validation | ||
|
||
|
||
@pytest.fixture | ||
def current_version(metadata_definition): | ||
return metadata_definition.data.dockerImageTag | ||
|
||
|
||
@pytest.fixture | ||
def decremented_version(current_version): | ||
version_info = semver.VersionInfo.parse(current_version) | ||
if version_info.major > 0: | ||
patched_version_info = version_info.replace(major=version_info.major - 1) | ||
elif version_info.minor > 0: | ||
patched_version_info = version_info.replace(major=version_info.minor - 1) | ||
elif version_info.patch > 0: | ||
patched_version_info = version_info.replace(patch=version_info.patch - 1) | ||
else: | ||
raise ValueError(f"Version {version_info} can't be decremented to prepare our test") | ||
return str(patched_version_info) | ||
|
||
|
||
@pytest.fixture | ||
def incremented_version(current_version): | ||
version_info = semver.VersionInfo.parse(current_version) | ||
if version_info.major > 0: | ||
patched_version_info = version_info.replace(major=version_info.major + 1) | ||
elif version_info.minor > 0: | ||
patched_version_info = version_info.replace(major=version_info.minor + 1) | ||
elif version_info.patch > 0: | ||
patched_version_info = version_info.replace(patch=version_info.patch + 1) | ||
else: | ||
raise ValueError(f"Version {version_info} can't be incremented to prepare our test") | ||
return str(patched_version_info) | ||
|
||
|
||
def test_validation_fail_on_docker_image_tag_decrement(metadata_definition, decremented_version): | ||
current_version = metadata_definition.data.dockerImageTag | ||
|
||
metadata_definition.data.dockerImageTag = decremented_version | ||
success, error_message = metadata_validator.validate_docker_image_tag_is_not_decremented(metadata_definition, None) | ||
assert not success | ||
assert error_message == f"The dockerImageTag value can't be decremented: it should be equal to or above {current_version}." | ||
|
||
|
||
def test_validation_pass_on_docker_image_tag_increment(metadata_definition, incremented_version): | ||
metadata_definition.data.dockerImageTag = incremented_version | ||
success, error_message = metadata_validator.validate_docker_image_tag_is_not_decremented(metadata_definition, None) | ||
assert success | ||
assert error_message is None | ||
|
||
|
||
def test_validation_pass_on_same_docker_image_tag(metadata_definition): | ||
success, error_message = metadata_validator.validate_docker_image_tag_is_not_decremented(metadata_definition, None) | ||
assert success | ||
assert error_message is None | ||
|
||
|
||
def test_validation_pass_on_docker_image_no_latest(capsys, metadata_definition): | ||
metadata_definition.data.dockerRepository = "airbyte/unreleased" | ||
success, error_message = metadata_validator.validate_docker_image_tag_is_not_decremented(metadata_definition, None) | ||
captured = capsys.readouterr() | ||
assert ( | ||
"https://registry.hub.docker.com/v2/repositories/airbyte/unreleased/tags returned a 404. The connector might not be released yet." | ||
in captured.out | ||
) | ||
assert success | ||
assert error_message is None |