|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +import jmespath |
| 20 | +from chart_utils.helm_template_generator import render_chart |
| 21 | + |
| 22 | + |
| 23 | +class TestTriggererPdb: |
| 24 | + """Tests Triggerer PDB.""" |
| 25 | + |
| 26 | + def test_should_pass_validation_with_just_pdb_enabled_v1(self): |
| 27 | + render_chart( |
| 28 | + values={"triggerer": {"podDisruptionBudget": {"enabled": True}}}, |
| 29 | + show_only=["templates/triggerer/triggerer-poddisruptionbudget.yaml"], |
| 30 | + ) # checks that no validation exception is raised |
| 31 | + |
| 32 | + def test_should_pass_validation_with_just_pdb_enabled_v1beta1(self): |
| 33 | + render_chart( |
| 34 | + values={"triggerer": {"podDisruptionBudget": {"enabled": True}}}, |
| 35 | + show_only=["templates/triggerer/triggerer-poddisruptionbudget.yaml"], |
| 36 | + kubernetes_version="1.16.0", |
| 37 | + ) # checks that no validation exception is raised |
| 38 | + |
| 39 | + def test_should_add_component_specific_labels(self): |
| 40 | + docs = render_chart( |
| 41 | + values={ |
| 42 | + "triggerer": { |
| 43 | + "podDisruptionBudget": {"enabled": True}, |
| 44 | + "labels": {"test_label": "test_label_value"}, |
| 45 | + }, |
| 46 | + }, |
| 47 | + show_only=["templates/triggerer/triggerer-poddisruptionbudget.yaml"], |
| 48 | + ) |
| 49 | + |
| 50 | + assert "test_label" in jmespath.search("metadata.labels", docs[0]) |
| 51 | + assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value" |
| 52 | + |
| 53 | + def test_should_pass_validation_with_pdb_enabled_and_min_available_param(self): |
| 54 | + render_chart( |
| 55 | + values={ |
| 56 | + "triggerer": { |
| 57 | + "podDisruptionBudget": { |
| 58 | + "enabled": True, |
| 59 | + "config": {"maxUnavailable": None, "minAvailable": 1}, |
| 60 | + } |
| 61 | + } |
| 62 | + }, |
| 63 | + show_only=["templates/triggerer/triggerer-poddisruptionbudget.yaml"], |
| 64 | + ) # checks that no validation exception is raised |
0 commit comments