Repository: apache/airflow
File: helm-tests/tests/helm_tests/airflow_aux/test_configmap.py (Python)

Code before:
        if expected_execution_url is not None:
            assert f"\nexecution_api_server_url = {expected_execution_url}\n" in config
        else:
            assert "execution_api_server_url" not in config, (
                "execution_api_server_url should not be set for Airflow 2.x versions"
            )

    @pytest.mark.parametrize(
        ("git_sync_enabled", "ssh_key_secret", "ssh_key", "expected_volume"),
        [
            (True, "my-secret", None, True),
            (True, None, "my-key", True),
            (True, "my-secret", "my-key", True),
            (True, None, None, False),
            (False, "my-secret", None, False),
            (False, None, "my-key", False),
        ],
    )
    def test_pod_template_git_sync_ssh_key_volume(
        self, git_sync_enabled, ssh_key_secret, ssh_key, expected_volume
    ):
        dag_values = {"gitSync": {"enabled": git_sync_enabled}}
        if ssh_key_secret:
            dag_values["gitSync"]["sshKeySecret"] = ssh_key_secret
        if ssh_key:
            dag_values["gitSync"]["sshKey"] = ssh_key

        docs = render_chart(
            values={
                "executor": "KubernetesExecutor",
                "dags": dag_values,
            },
            show_only=["templates/configmaps/configmap.yaml"],
        )

        pod_template_file = jmespath.search('data."pod_template_file.yaml"', docs[0])
        if expected_volume:
            assert "git-sync-ssh-key" in pod_template_file
        else:
            assert "git-sync-ssh-key" not in pod_template_file

    @pytest.mark.parametrize(
        ("scheduler_cpu_limit", "expected_sync_parallelism"),
        [
            ("1m", "1"),
            ("1000m", "1"),
            ("1001m", "2"),
            ("0.1", "1"),
            ("1", "1"),
            ("1.01", "2"),
            (None, 0),

Review comment (security):
Let's split this test into two test cases based on the settings (`sshKeySecret` or `sshKey`) that we set. It will be more readable, and in general, there should be no logic in tests

Code after:
        if expected_execution_url is not None:
            assert f"\nexecution_api_server_url = {expected_execution_url}\n" in config
        else:
            assert "execution_api_server_url" not in config, (
                "execution_api_server_url should not be set for Airflow 2.x versions"
            )

    @pytest.mark.parametrize(
        ("git_sync_enabled", "ssh_key_secret", "expected_volume"),
        [
            (True, "my-secret", True),
            (True, None, False),
            (False, "my-secret", False),
        ],
    )
    def test_pod_template_git_sync_ssh_key_volume_with_ssh_key_secret_name(
        self, git_sync_enabled, ssh_key_secret, expected_volume
    ):
        dag_values = {"gitSync": {"enabled": git_sync_enabled, "sshKeySecret": ssh_key_secret}}
        docs = render_chart(
            values={
                "executor": "KubernetesExecutor",
                "dags": dag_values,
            },
            show_only=["templates/configmaps/configmap.yaml"],
        )

        pod_template_file = jmespath.search('data."pod_template_file.yaml"', docs[0])
        assert ("git-sync-ssh-key" in pod_template_file) == expected_volume

    @pytest.mark.parametrize(
        ("git_sync_enabled", "ssh_key", "expected_volume"),
        [
            (True, "my-key", True),
            (True, None, False),
            (False, "my-key", False),
        ],
    )
    def test_pod_template_git_sync_ssh_key_volume_with_ssh_key(
        self, git_sync_enabled, ssh_key, expected_volume
    ):
        dag_values = {"gitSync": {"enabled": git_sync_enabled, "sshKey": ssh_key}}
        docs = render_chart(
            values={
                "executor": "KubernetesExecutor",
                "dags": dag_values,
            },
            show_only=["templates/configmaps/configmap.yaml"],
        )

        pod_template_file = jmespath.search('data."pod_template_file.yaml"', docs[0])