You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/10/20 21:45:53 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #11694: Create pytest fixtures for testing Helm chart templates

mik-laj commented on a change in pull request #11694:
URL: https://github.com/apache/airflow/pull/11694#discussion_r508859361



##########
File path: chart/tests/conftest.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.
+
+import logging
+import os
+import subprocess
+from typing import Dict, List, Optional
+
+import pytest
+import yaml
+
+log = logging.getLogger(__name__)
+
+CHART_FOLDER = os.path.normpath(os.path.join(__file__, os.pardir, os.pardir))
+
+
+def run_cmd(cmd, **kwargs):
+    """
+    Helper method to run a command, and include any output in case of error.
+    """
+    try:
+        log.debug('Running %s', cmd)
+        return subprocess.check_output(
+            cmd,
+            stderr=subprocess.STDOUT,
+            **kwargs
+        )
+    except subprocess.CalledProcessError as e:
+        raise AssertionError(f'Command {cmd} failed with: {e.output.decode("utf-8")}')
+
+
+@pytest.fixture(scope="session", autouse=True)
+def initalize_chart():
+    """
+    Get the helm chart ready to install/render.
+
+    This is run for us automatically by pytest once per test-session
+    """
+    run_cmd(['helm', 'repo', 'add', 'stable', 'https://kubernetes-charts.storage.googleapis.com/'])
+    run_cmd(['helm', 'dep', 'update', CHART_FOLDER])
+
+
+@pytest.fixture
+def render_chart(request):

Review comment:
       I don't know if I wouldn't prefer the templates used to be always explicit passed. Many of the contributions we have to the Helm Chart are small and made by many different contributors. I don't want them to have to learn new concepts if it's not needed. Tests for templates are already a high threshold for entering the project. This is not common in all projects.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org