Skip to content

Commit

Permalink
Refactor meta-incorrect tests (#3266)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ajinkya Udgirkar <ajinkyaudgirkar@gmail.com>
  • Loading branch information
3 people committed Apr 11, 2023
1 parent f0f198a commit 96d1914
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Expand Up @@ -59,7 +59,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 798
PYTEST_REQPASS: 797
steps:
- name: Activate WSL1
if: "contains(matrix.shell, 'wsl')"
Expand Down
12 changes: 12 additions & 0 deletions examples/roles/meta_incorrect_fail/meta/main.yml
@@ -0,0 +1,12 @@
# Fixture for meta-incorrect
---
galaxy_info: # <-- 4x meta-incorrect
author: your name
description: your description
company: your company (optional)
license: license (GPLv2, CC-BY, etc)
min_ansible_version: "2.12"
platforms:
- name: EL
versions:
- "7"
22 changes: 22 additions & 0 deletions src/ansiblelint/rules/meta_incorrect.py
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2018, Ansible Project
from __future__ import annotations

import sys
from typing import TYPE_CHECKING

from ansiblelint.constants import LINE_NUMBER_KEY
Expand Down Expand Up @@ -54,3 +55,24 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
)

return results


if "pytest" in sys.modules:
from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports

def test_default_galaxy_info(
default_rules_collection: RulesCollection,
) -> None:
"""Test for meta-incorrect."""
results = Runner(
"examples/roles/meta_incorrect_fail", rules=default_rules_collection
).run()
for result in results:
assert result.rule.id == "meta-incorrect"
assert len(results) == 4

assert "Should change default metadata: author" in str(results)
assert "Should change default metadata: description" in str(results)
assert "Should change default metadata: company" in str(results)
assert "Should change default metadata: license" in str(results)
6 changes: 0 additions & 6 deletions src/ansiblelint/rules/meta_video_links.py
Expand Up @@ -85,12 +85,6 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
if "pytest" in sys.modules:
import pytest

META_NO_GALAXY_INFO = """
galaxy_information:
video_links:
- url: https://www.youtube.com/watch?v=aWmRepTSFKs&feature=youtu.be
"""

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports

Expand Down
42 changes: 0 additions & 42 deletions test/rules/test_meta_change_from_default.py

This file was deleted.

0 comments on commit 96d1914

Please sign in to comment.