2023-08-03 08:52:14 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from operator_repo import Bundle, Repo
|
|
|
|
from operator_repo.exceptions import InvalidBundleException, InvalidOperatorException
|
|
|
|
from tests import bundle_files, create_files
|
|
|
|
|
|
|
|
|
|
|
|
def test_bundle(tmp_path: Path) -> None:
|
|
|
|
create_files(
|
|
|
|
tmp_path,
|
|
|
|
bundle_files("hello", "0.0.1"),
|
|
|
|
)
|
|
|
|
repo = Repo(tmp_path)
|
|
|
|
operator = repo.operator("hello")
|
|
|
|
bundle = operator.bundle("0.0.1")
|
2023-08-04 07:06:39 +00:00
|
|
|
assert bundle.root == operator.root / "0.0.1"
|
2023-08-03 08:52:14 +00:00
|
|
|
assert bundle.csv_operator_name == "hello"
|
|
|
|
assert bundle.csv_operator_version == "0.0.1"
|
|
|
|
assert (
|
|
|
|
bundle.annotations["operators.operatorframework.io.bundle.package.v1"]
|
|
|
|
== "hello"
|
|
|
|
)
|
|
|
|
assert bundle.dependencies == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_bundle_compare(tmp_path: Path) -> None:
|
|
|
|
create_files(
|
|
|
|
tmp_path,
|
|
|
|
bundle_files("hello", "0.0.1"),
|
|
|
|
bundle_files("hello", "0.0.2"),
|
|
|
|
bundle_files("world", "0.1.0"),
|
|
|
|
)
|
|
|
|
repo = Repo(tmp_path)
|
|
|
|
operator_hello = repo.operator("hello")
|
|
|
|
operator_world = repo.operator("world")
|
|
|
|
assert operator_hello == repo.operator("hello")
|
|
|
|
assert operator_hello != operator_world
|
|
|
|
assert operator_hello < operator_world
|
|
|
|
hello_bundle_1 = operator_hello.bundle("0.0.1")
|
|
|
|
hello_bundle_2 = operator_hello.bundle("0.0.2")
|
|
|
|
world_bundle_1 = operator_world.bundle("0.1.0")
|
|
|
|
assert hello_bundle_1 != hello_bundle_2
|
|
|
|
assert hello_bundle_1 < hello_bundle_2
|
|
|
|
assert hello_bundle_1 != world_bundle_1
|
2023-08-03 17:23:45 +00:00
|
|
|
assert hello_bundle_1 < world_bundle_1
|
2023-08-03 08:52:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_bundle_non_semver(tmp_path: Path) -> None:
|
|
|
|
create_files(
|
|
|
|
tmp_path,
|
|
|
|
bundle_files("hello", "0.0.99.0"),
|
|
|
|
bundle_files("hello", "0.0.100.0"),
|
|
|
|
)
|
|
|
|
repo = Repo(tmp_path)
|
|
|
|
operator = repo.operator("hello")
|
|
|
|
bundle_99 = operator.bundle("0.0.99.0")
|
|
|
|
bundle_100 = operator.bundle("0.0.100.0")
|
|
|
|
assert bundle_99 > bundle_100
|
|
|
|
|
|
|
|
|
|
|
|
def test_bundle_invalid(tmp_path: Path) -> None:
|
|
|
|
create_files(
|
|
|
|
tmp_path,
|
|
|
|
bundle_files(
|
|
|
|
"invalid_csv_name", "0.0.1", csv={"metadata": {"name": "rubbish"}}
|
|
|
|
),
|
|
|
|
{
|
|
|
|
"operators/missing_manifests/0.0.1/metadata/annotations.yaml": {
|
|
|
|
"annotations": {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bundle_files("invalid_csv_contents", "0.0.1"),
|
|
|
|
{
|
|
|
|
"operators/invalid_csv_contents/0.0.1/manifests/invalid_csv_contents.clusterserviceversion.yaml": [],
|
|
|
|
},
|
|
|
|
bundle_files("invalid_metadata_contents", "0.0.1"),
|
|
|
|
{
|
|
|
|
"operators/invalid_metadata_contents/0.0.1/metadata/annotations.yaml": [],
|
|
|
|
},
|
|
|
|
bundle_files("empty_metadata", "0.0.1"),
|
|
|
|
{
|
|
|
|
"operators/empty_metadata/0.0.1/metadata/annotations.yaml": "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"operators/missing_csv/0.0.1/metadata/annotations.yaml": {
|
|
|
|
"annotations": {}
|
|
|
|
},
|
|
|
|
"operators/missing_csv/0.0.1/manifests": None,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
repo = Repo(tmp_path)
|
|
|
|
with pytest.raises(InvalidBundleException, match="has invalid .metadata.name"):
|
|
|
|
_ = repo.operator("invalid_csv_name").bundle("0.0.1").csv_operator_name
|
|
|
|
assert not repo.has("missing_manifests")
|
|
|
|
with pytest.raises(InvalidBundleException, match="Not a valid bundle"):
|
2023-08-04 07:06:39 +00:00
|
|
|
_ = Bundle(repo.root / "operators" / "missing_manifests" / "0.0.1")
|
2023-08-03 08:52:14 +00:00
|
|
|
with pytest.raises(InvalidOperatorException, match="Not a valid operator"):
|
|
|
|
_ = repo.operator("missing_manifests")
|
|
|
|
assert repo.has("invalid_csv_contents")
|
|
|
|
with pytest.raises(InvalidBundleException, match="Invalid CSV contents"):
|
|
|
|
_ = repo.operator("invalid_csv_contents").bundle("0.0.1").csv_operator_version
|
|
|
|
with pytest.raises(InvalidBundleException, match="Invalid .* contents"):
|
|
|
|
_ = repo.operator("invalid_metadata_contents").bundle("0.0.1").annotations
|
|
|
|
assert repo.operator("empty_metadata").bundle("0.0.1").annotations == {}
|
|
|
|
assert repo.has("missing_csv")
|
|
|
|
with pytest.raises(InvalidBundleException, match="CSV file for .* not found"):
|
|
|
|
_ = repo.operator("missing_csv").bundle("0.0.1").csv_operator_name
|