From 2fe34b6444502079dc0b84365ce82dbc92de308e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:06:49 +0200 Subject: Adding upstream version 6.17.2. Signed-off-by: Daniel Baumann --- test/test_app.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/test_app.py (limited to 'test/test_app.py') diff --git a/test/test_app.py b/test/test_app.py new file mode 100644 index 0000000..140f5f6 --- /dev/null +++ b/test/test_app.py @@ -0,0 +1,30 @@ +"""Test for app module.""" +from pathlib import Path + +from ansiblelint.constants import RC +from ansiblelint.file_utils import Lintable +from ansiblelint.testing import run_ansible_lint + + +def test_generate_ignore(tmp_path: Path) -> None: + """Validate that --generate-ignore dumps expected ignore to the file.""" + lintable = Lintable(tmp_path / "vars.yaml") + lintable.content = "foo: bar\nfoo: baz\n" + lintable.write(force=True) + ignore_file = tmp_path / ".ansible-lint-ignore" + assert not ignore_file.exists() + result = run_ansible_lint(lintable.filename, "--generate-ignore", cwd=tmp_path) + assert result.returncode == 2 + + assert ignore_file.exists() + with ignore_file.open(encoding="utf-8") as f: + assert "vars.yaml yaml[key-duplicates]\n" in f.readlines() + # Run again and now we expect to succeed as we have an ignore file. + result = run_ansible_lint(lintable.filename, cwd=tmp_path) + assert result.returncode == 0 + + +def test_app_no_matches(tmp_path: Path) -> None: + """Validate that linter returns special exit code if no files are analyzed.""" + result = run_ansible_lint(cwd=tmp_path) + assert result.returncode == RC.NO_FILES_MATCHED -- cgit v1.2.3