|
10 | 10 |
|
11 | 11 |
|
12 | 12 | @pytest.mark.parametrize( |
13 | | - "annotation_package,csv_package,expected", |
| 13 | + "files, bundle_to_check, expected_results", |
14 | 14 | [ |
15 | | - pytest.param("foo", "foo", set(), id="Name matches"), |
16 | 15 | pytest.param( |
17 | | - "foo", |
18 | | - "bar", |
| 16 | + [ |
| 17 | + bundle_files("hello", "0.0.1"), |
| 18 | + ], |
| 19 | + ("hello", "0.0.1"), |
| 20 | + set(), |
| 21 | + id="Names ok", |
| 22 | + ), |
| 23 | + pytest.param( |
| 24 | + [ |
| 25 | + bundle_files( |
| 26 | + "hello", |
| 27 | + "0.0.1", |
| 28 | + annotations={ |
| 29 | + "operators.operatorframework.io.bundle.package.v1": "foo" |
| 30 | + }, |
| 31 | + ), |
| 32 | + ], |
| 33 | + ("hello", "0.0.1"), |
| 34 | + { |
| 35 | + ( |
| 36 | + Fail, |
| 37 | + "Operator name from annotations.yaml (foo) does not match" |
| 38 | + " the operator's directory name (hello)", |
| 39 | + ), |
| 40 | + ( |
| 41 | + Fail, |
| 42 | + "Operator name from annotations.yaml (foo) does not match" |
| 43 | + " the name defined in the CSV (hello)", |
| 44 | + ), |
| 45 | + }, |
| 46 | + id="Wrong annotations.yaml name", |
| 47 | + ), |
| 48 | + pytest.param( |
| 49 | + [ |
| 50 | + bundle_files("hello", "0.0.1"), |
| 51 | + { |
| 52 | + "operators/hello/0.0.1/metadata/annotations.yaml": { |
| 53 | + "annotations": {} |
| 54 | + } |
| 55 | + }, |
| 56 | + ], |
| 57 | + ("hello", "0.0.1"), |
| 58 | + { |
| 59 | + (Fail, "Bundle does not define the operator name in annotations.yaml"), |
| 60 | + }, |
| 61 | + id="Empty annotations.yaml", |
| 62 | + ), |
| 63 | + pytest.param( |
| 64 | + [ |
| 65 | + bundle_files("hello", "0.0.1"), |
| 66 | + bundle_files( |
| 67 | + "hello", |
| 68 | + "0.0.2", |
| 69 | + annotations={ |
| 70 | + "operators.operatorframework.io.bundle.package.v1": "foo" |
| 71 | + }, |
| 72 | + ), |
| 73 | + bundle_files( |
| 74 | + "hello", |
| 75 | + "0.0.3", |
| 76 | + annotations={ |
| 77 | + "operators.operatorframework.io.bundle.package.v1": "foo" |
| 78 | + }, |
| 79 | + ), |
| 80 | + ], |
| 81 | + ("hello", "0.0.3"), |
| 82 | + { |
| 83 | + ( |
| 84 | + Warn, |
| 85 | + "Operator name from annotations.yaml (foo) does not match" |
| 86 | + " the operator's directory name (hello)", |
| 87 | + ), |
| 88 | + ( |
| 89 | + Warn, |
| 90 | + "Operator name from annotations.yaml (foo) does not match" |
| 91 | + " the name defined in the CSV (hello)", |
| 92 | + ), |
| 93 | + ( |
| 94 | + Warn, |
| 95 | + "Operator name from annotations.yaml is not consistent" |
| 96 | + " across bundles: ['foo', 'hello']", |
| 97 | + ), |
| 98 | + }, |
| 99 | + id="Wrong annotations.yaml name, inconsistent bundles", |
| 100 | + ), |
| 101 | + pytest.param( |
| 102 | + [ |
| 103 | + bundle_files("hello", "0.0.1"), |
| 104 | + bundle_files( |
| 105 | + "hello", |
| 106 | + "0.0.2", |
| 107 | + csv={"metadata": {"name": "foo.v0.0.2"}}, |
| 108 | + ), |
| 109 | + bundle_files( |
| 110 | + "hello", |
| 111 | + "0.0.3", |
| 112 | + csv={"metadata": {"name": "foo.v0.0.3"}}, |
| 113 | + ), |
| 114 | + ], |
| 115 | + ("hello", "0.0.3"), |
| 116 | + { |
| 117 | + ( |
| 118 | + Warn, |
| 119 | + "Operator name from annotations.yaml (hello) does not match" |
| 120 | + " the name defined in the CSV (foo)", |
| 121 | + ), |
| 122 | + ( |
| 123 | + Warn, |
| 124 | + "Operator name from the CSV is not consistent across bundles: ['foo', 'hello']", |
| 125 | + ), |
| 126 | + }, |
| 127 | + id="Wrong CSV name, inconsistent bundles", |
| 128 | + ), |
| 129 | + pytest.param( |
| 130 | + [ |
| 131 | + bundle_files("hello", "0.0.1"), |
| 132 | + bundle_files("hello", "0.0.2"), |
| 133 | + bundle_files( |
| 134 | + "hello", |
| 135 | + "0.0.3", |
| 136 | + annotations={ |
| 137 | + "operators.operatorframework.io.bundle.package.v1": "foo" |
| 138 | + }, |
| 139 | + ), |
| 140 | + ], |
| 141 | + ("hello", "0.0.3"), |
19 | 142 | { |
20 | | - Warn( |
21 | | - "Bundle package annotation is set to 'foo'. Expected value " |
22 | | - "is 'bar' based on the CSV name. To fix this issue define " |
23 | | - "the annotation in 'metadata/annotations.yaml' file that " |
24 | | - "matches the CSV name." |
25 | | - ) |
| 143 | + ( |
| 144 | + Fail, |
| 145 | + "Operator name from annotations.yaml (foo) does not match" |
| 146 | + " the operator's directory name (hello)", |
| 147 | + ), |
| 148 | + ( |
| 149 | + Fail, |
| 150 | + "Operator name from annotations.yaml (foo) does not match" |
| 151 | + " the name defined in the CSV (hello)", |
| 152 | + ), |
| 153 | + ( |
| 154 | + Fail, |
| 155 | + "Operator name from annotations.yaml (foo) does not match" |
| 156 | + " the name defined in other bundles (hello)", |
| 157 | + ), |
26 | 158 | }, |
27 | | - id="Name does not match", |
| 159 | + id="Wrong annotations.yaml name, consistent bundles", |
| 160 | + ), |
| 161 | + pytest.param( |
| 162 | + [ |
| 163 | + bundle_files("hello", "0.0.1"), |
| 164 | + bundle_files("hello", "0.0.2"), |
| 165 | + bundle_files( |
| 166 | + "hello", |
| 167 | + "0.0.3", |
| 168 | + csv={"metadata": {"name": "foo.v0.0.3"}}, |
| 169 | + ), |
| 170 | + ], |
| 171 | + ("hello", "0.0.3"), |
| 172 | + { |
| 173 | + ( |
| 174 | + Fail, |
| 175 | + "Operator name from annotations.yaml (hello) does not match" |
| 176 | + " the name defined in the CSV (foo)", |
| 177 | + ), |
| 178 | + ( |
| 179 | + Fail, |
| 180 | + "Operator name from the CSV (foo) does not match the name" |
| 181 | + " defined in other bundles (hello)", |
| 182 | + ), |
| 183 | + }, |
| 184 | + id="Wrong CSV name, consistent bundles", |
28 | 185 | ), |
29 | 186 | ], |
| 187 | + indirect=False, |
30 | 188 | ) |
31 | | -def test_check_operator_name( |
32 | | - annotation_package: str, csv_package: str, expected: Any, tmp_path: Path |
| 189 | +def test_operator_name( |
| 190 | + tmp_path: Path, |
| 191 | + files: list[dict[str, Any]], |
| 192 | + bundle_to_check: tuple[str, str], |
| 193 | + expected_results: set[tuple[type, str]], |
33 | 194 | ) -> None: |
34 | | - annotations = { |
35 | | - "operators.operatorframework.io.bundle.package.v1": annotation_package, |
36 | | - } |
37 | | - create_files(tmp_path, bundle_files(csv_package, "0.0.1", annotations=annotations)) |
38 | | - |
| 195 | + create_files(tmp_path, *files) |
39 | 196 | repo = Repo(tmp_path) |
40 | | - bundle = repo.operator(csv_package).bundle("0.0.1") |
41 | | - |
42 | | - assert set(check_operator_name(bundle)) == expected |
| 197 | + operator_name, bundle_version = bundle_to_check |
| 198 | + operator = repo.operator(operator_name) |
| 199 | + bundle = operator.bundle(bundle_version) |
| 200 | + assert { |
| 201 | + (x.__class__, x.reason) for x in check_operator_name(bundle) |
| 202 | + } == expected_results |
0 commit comments