From fc9cbf7c932c985a6cf379ecd7a68affca7568d2 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Thu, 11 Jan 2024 15:45:09 -0800 Subject: [PATCH] Fix unit tests --- lint-workflow/tests/rules/test_job_environment_prefix.py | 4 ++-- lint-workflow/tests/rules/test_name_capitalized.py | 6 +++--- lint-workflow/tests/rules/test_name_exists.py | 1 - lint-workflow/tests/rules/test_pinned_job_runner.py | 4 ++-- lint-workflow/tests/rules/test_step_approved.py | 4 ++-- lint-workflow/tests/rules/test_step_pinned.py | 4 ++-- lint-workflow/tests/test_rule.py | 9 ++------- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lint-workflow/tests/rules/test_job_environment_prefix.py b/lint-workflow/tests/rules/test_job_environment_prefix.py index 87528ffa..c77478f6 100644 --- a/lint-workflow/tests/rules/test_job_environment_prefix.py +++ b/lint-workflow/tests/rules/test_job_environment_prefix.py @@ -26,7 +26,7 @@ def correct_workflow(): steps: - run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -44,7 +44,7 @@ def incorrect_workflow(): steps: - run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture diff --git a/lint-workflow/tests/rules/test_name_capitalized.py b/lint-workflow/tests/rules/test_name_capitalized.py index 1a4f3849..a496507d 100644 --- a/lint-workflow/tests/rules/test_name_capitalized.py +++ b/lint-workflow/tests/rules/test_name_capitalized.py @@ -28,7 +28,7 @@ def correct_workflow(): - name: Test run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -47,7 +47,7 @@ def incorrect_workflow(): - name: test run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -63,7 +63,7 @@ def missing_name_workflow(): steps: - run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture diff --git a/lint-workflow/tests/rules/test_name_exists.py b/lint-workflow/tests/rules/test_name_exists.py index 3853326a..1634acc4 100644 --- a/lint-workflow/tests/rules/test_name_exists.py +++ b/lint-workflow/tests/rules/test_name_exists.py @@ -1,5 +1,4 @@ import pytest - from ..conftest import FIXTURE_DIR from ..context import src diff --git a/lint-workflow/tests/rules/test_pinned_job_runner.py b/lint-workflow/tests/rules/test_pinned_job_runner.py index 18cd1fc1..59d0b93e 100644 --- a/lint-workflow/tests/rules/test_pinned_job_runner.py +++ b/lint-workflow/tests/rules/test_pinned_job_runner.py @@ -24,7 +24,7 @@ def correct_runner(): steps: - run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -40,7 +40,7 @@ def incorrect_runner(): steps: - run: echo test """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture diff --git a/lint-workflow/tests/rules/test_step_approved.py b/lint-workflow/tests/rules/test_step_approved.py index 7f2d83a7..2c3ba039 100644 --- a/lint-workflow/tests/rules/test_step_approved.py +++ b/lint-workflow/tests/rules/test_step_approved.py @@ -54,7 +54,7 @@ def correct_workflow(): - name: Test Run Action run: echo "test" """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -74,7 +74,7 @@ def incorrect_workflow(): - name: Out of date action uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0 """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture diff --git a/lint-workflow/tests/rules/test_step_pinned.py b/lint-workflow/tests/rules/test_step_pinned.py index c917c769..673985d7 100644 --- a/lint-workflow/tests/rules/test_step_pinned.py +++ b/lint-workflow/tests/rules/test_step_pinned.py @@ -34,7 +34,7 @@ def correct_workflow(): - name: Test Run Action run: echo "test" """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture @@ -57,7 +57,7 @@ def incorrect_workflow(): - name: Test Internal Commit uses: bitwarden/gh-actions/get-keyvault-secrets@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 """ - return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False) + return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) @pytest.fixture diff --git a/lint-workflow/tests/test_rule.py b/lint-workflow/tests/test_rule.py index 4e0fa471..176ad19a 100644 --- a/lint-workflow/tests/test_rule.py +++ b/lint-workflow/tests/test_rule.py @@ -5,7 +5,7 @@ from ruamel.yaml import YAML from src.load import WorkflowBuilder -from src.rule import Rule +from src.rule import Rule, RuleExecutionException from src.models import Workflow, Job, Step @@ -65,18 +65,13 @@ def fn(self, obj: Union[Workflow, Job, Step]) -> bool: return obj.name is not None, self.message -class TestException(Exception): - """Test Exception.""" - pass - - class RuleException(Rule): def __init__(self): self.message = "should raise Exception" self.on_fail = "error" def fn(self, obj: Union[Workflow, Job, Step]) -> bool: - raise TestException("test Exception") + raise RuleExecutionException("test Exception") @pytest.fixture(name="step_rule")