File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -344,6 +344,14 @@ def check_replaces_availability(bundle: Bundle) -> Iterator[CheckResult]:
344344 x .csv_operator_version : x .operator_version
345345 for x in bundle .operator .all_bundles ()
346346 }
347+
348+ if replaces_version not in ver_to_dir :
349+ yield Fail (
350+ f"{ bundle } attempts to replace version '{ replaces_version } ' which"
351+ f" does not exist. Available versions: { sorted (ver_to_dir .keys ())} "
352+ )
353+ return
354+
347355 replaces_bundle = bundle .operator .bundle (ver_to_dir [replaces_version ])
348356
349357 ocp_versions_str = bundle .annotations .get ("com.redhat.openshift.versions" )
Original file line number Diff line number Diff line change @@ -606,6 +606,34 @@ def test_check_replaces_availability(
606606 assert set (errors ) == expected
607607
608608
609+ def test_check_replaces_availability_nonexistent_version (
610+ tmp_path : Path ,
611+ ) -> None :
612+ """Test that attempting to replace a non-existent version produces a clear error message"""
613+ create_files (
614+ tmp_path ,
615+ bundle_files ("hello" , "0.0.1" ),
616+ bundle_files (
617+ "hello" ,
618+ "0.0.2" ,
619+ csv = {"spec" : {"replaces" : "hello.v0.0.5" }}, # 0.0.5 doesn't exist
620+ ),
621+ )
622+
623+ repo = Repo (tmp_path )
624+ operator = repo .operator ("hello" )
625+ bundle = operator .bundle ("0.0.2" )
626+ errors = list (check_replaces_availability (bundle ))
627+
628+ assert len (errors ) == 1
629+ assert isinstance (errors [0 ], Fail )
630+ assert (
631+ "Bundle(hello/0.0.2) attempts to replace version '0.0.5' which does not exist"
632+ in errors [0 ].reason
633+ )
634+ assert "Available versions:" in errors [0 ].reason
635+
636+
609637@pytest .mark .parametrize (
610638 "files, bundle_to_check, expected" ,
611639 [
You can’t perform that action at this time.
0 commit comments