Skip to content

Apache DataFusion SQL Query Engine

2.0 KB
Raw Blame
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
# SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements

"""Regression tests for the Rust workflow skip policies."""

import unittest
from pathlib import Path

import yaml

from check_asf_yaml_status_checks import get_required_checks
from check_rust_workflow_skips import check_skip_conditions

ROOT = Path(__file__).resolve().parents[2]


class RustWorkflowSkipsTest(unittest.TestCase):
    def setUp(self):
        self.workflow = yaml.safe_load((ROOT / ".github/workflows/rust.yml").read_text())
        self.required_checks = get_required_checks(ROOT / ".asf.yaml")

    def errors(self):
        return check_skip_conditions(self.workflow, self.required_checks)

    def test_current_workflow(self):
        self.assertEqual(self.errors(), [])

    def test_missing_skip_guard(self):
        del self.workflow["jobs"]["linux-test"]["if"]
        self.assertTrue(
            any("job `linux-test` must carry exactly" in error for error in self.errors())
        )

    def test_unskipped_job_needs_skipped_job(self):
        self.workflow["jobs"]["check-fmt"]["needs"] = "linux-test"
        self.assertIn(
            "  - job `check-fmt` is not in FORK_PR_SKIPPED_JOBS but needs "
            "['linux-test']; GitHub would skip it with them",
            self.errors(),
        )

    def test_missing_artifact_upload_guard(self):
        upload = next(
            step
            for step in self.workflow["jobs"]["linux-build-lib"]["steps"]
            if step.get("uses", "").startswith("actions/upload-artifact")
            and step.get("with", {}).get("name") == "cargo-check"
        )
        del upload["if"]
        self.assertTrue(
            any("`cargo-check` upload step" in error for error in self.errors())
        )


if __name__ == "__main__":
    unittest.main()