jedcunningham commented on code in PR #34716: URL: https://github.com/apache/airflow/pull/34716#discussion_r1355248925
########## helm_tests/webserver/test_httproute_flower.py: ########## @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import jmespath +import pytest + +from tests.charts.helm_template_generator import render_chart + + +class TestHttpRouteFlower: + """Tests httpRoute flower.""" + + def test_should_pass_validation_with_httproute_enabled_and_gateway_set(self): + render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) # checks that no validation exception is raised + Review Comment: ```suggestion ``` I'm not sure we need this test when we have the next one. Each test isn't that big, but in total they add up. ########## helm_tests/webserver/test_httproute_flower.py: ########## @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import jmespath +import pytest + +from tests.charts.helm_template_generator import render_chart + + +class TestHttpRouteFlower: + """Tests httpRoute flower.""" + + def test_should_pass_validation_with_httproute_enabled_and_gateway_set(self): + render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) # checks that no validation exception is raised + + def test_should_check_that_both_httproute_and_healthcheckpolicy_are_created(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert 2 == len(docs) + assert "HTTPRoute" == jmespath.search("kind", docs[0]) + assert "HealthCheckPolicy" == jmespath.search("kind", docs[1]) + + def test_should_allow_more_than_one_annotation(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "annotations": {"aa": "bb", "cc": "dd"}, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert {"aa": "bb", "cc": "dd"} == jmespath.search("metadata.annotations", docs[0]) + + def test_should_set_httproute_gateway_name(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "foo", "namespace": "bar"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert "foo" == jmespath.search("spec.parentRefs[0].name", docs[0]) + + def test_should_httproute_hostnames_entry_not_exist(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert not jmespath.search("spec.hostnames", docs[0]) Review Comment: Should we have a test that hostnames do get added as well? ########## helm_tests/webserver/test_httproute_flower.py: ########## @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import jmespath +import pytest + +from tests.charts.helm_template_generator import render_chart + + +class TestHttpRouteFlower: + """Tests httpRoute flower.""" + + def test_should_pass_validation_with_httproute_enabled_and_gateway_set(self): + render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) # checks that no validation exception is raised + + def test_should_check_that_both_httproute_and_healthcheckpolicy_are_created(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert 2 == len(docs) + assert "HTTPRoute" == jmespath.search("kind", docs[0]) + assert "HealthCheckPolicy" == jmespath.search("kind", docs[1]) + + def test_should_allow_more_than_one_annotation(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "annotations": {"aa": "bb", "cc": "dd"}, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert {"aa": "bb", "cc": "dd"} == jmespath.search("metadata.annotations", docs[0]) + + def test_should_set_httproute_gateway_name(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "foo", "namespace": "bar"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert "foo" == jmespath.search("spec.parentRefs[0].name", docs[0]) + + def test_should_httproute_hostnames_entry_not_exist(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert not jmespath.search("spec.hostnames", docs[0]) + + @pytest.mark.parametrize( + "value, expected", + [ + (None, False), + (False, False), + (True, True), + ], + ) + def test_httproute_created(self, value, expected): + values={"httpRoute": {"flower": {"gateway": {"name": "test-gateway", "namespace": "test"}}}} + if value is not None: + values["httpRoute"]["flower"]["enabled"] = value + docs = render_chart(values=values, show_only=["templates/flower/flower-httproute.yaml"]) + assert expected == (2 == len(docs)) + + def test_should_add_component_specific_labels(self): + docs = render_chart( + values={ + "httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}, + "flower": { + "labels": {"test_label": "test_label_value"}, + }, + }, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert "test_label" in jmespath.search("metadata.labels", docs[0]) + assert jmespath.search("metadata.labels", docs[0])["test_label"] == "test_label_value" Review Comment: Shouldn't we check the HealthCheckPolicy also? ########## chart/templates/flower/flower-httproute.yaml: ########## @@ -0,0 +1,82 @@ +{{/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/}} + +################################ +## Airflow Flower HTTPRoute +################################# +{{- if .Values.httpRoute.flower.enabled }} +{{- $fullname := (include "airflow.fullname" .) }} +kind: HTTPRoute +apiVersion: gateway.networking.k8s.io/v1beta1 +metadata: + name: {{ $fullname }}-httproute Review Comment: Shouldn't this name be specific to flower? What if someone wanted to enable both? ########## helm_tests/webserver/test_httproute_flower.py: ########## @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import jmespath +import pytest + +from tests.charts.helm_template_generator import render_chart + + +class TestHttpRouteFlower: + """Tests httpRoute flower.""" + + def test_should_pass_validation_with_httproute_enabled_and_gateway_set(self): + render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) # checks that no validation exception is raised + + def test_should_check_that_both_httproute_and_healthcheckpolicy_are_created(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert 2 == len(docs) + assert "HTTPRoute" == jmespath.search("kind", docs[0]) + assert "HealthCheckPolicy" == jmespath.search("kind", docs[1]) + + def test_should_allow_more_than_one_annotation(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "annotations": {"aa": "bb", "cc": "dd"}, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert {"aa": "bb", "cc": "dd"} == jmespath.search("metadata.annotations", docs[0]) + + def test_should_set_httproute_gateway_name(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "foo", "namespace": "bar"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert "foo" == jmespath.search("spec.parentRefs[0].name", docs[0]) + + def test_should_httproute_hostnames_entry_not_exist(self): + docs = render_chart( + values={"httpRoute": {"flower": {"enabled": True, + "gateway": {"name": "test-gateway", "namespace": "test"}}}}, + show_only=["templates/flower/flower-httproute.yaml"], + ) + assert not jmespath.search("spec.hostnames", docs[0]) + + @pytest.mark.parametrize( + "value, expected", + [ + (None, False), + (False, False), + (True, True), + ], + ) + def test_httproute_created(self, value, expected): + values={"httpRoute": {"flower": {"gateway": {"name": "test-gateway", "namespace": "test"}}}} + if value is not None: + values["httpRoute"]["flower"]["enabled"] = value + docs = render_chart(values=values, show_only=["templates/flower/flower-httproute.yaml"]) + assert expected == (2 == len(docs)) Review Comment: It might be better to actually assert the count directly. If you got 1 doc and checked "false" it'd still match. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
