"""test lint commands.""" import json import shutil from collections.abc import Generator from pathlib import Path from typing import Any import pytest from tests.integration.utils import run_command @pytest.fixture() def testdir(tmp_path: Path) -> Generator[Path, None, None]: d = tmp_path / "testdata" if d.is_dir(): shutil.rmtree(d) d.mkdir() yield d shutil.rmtree(d) def test_lint_validate(testdir: Path) -> None: """Test greetings bonjour command works.""" m2m_json_file = testdir / "m2m.json" m2m_json_contents = json.dumps( [ { "name": "pp-m2m-config-test-machine-to-machine", "prod_aws_account": "437795906767", "qa_aws_account": "437795906767", "client_metadata": { "m2m_identity_uuid": "1a6f06cd-cc30-4252-8654-cb93a9843b38" }, } ] ) m2m_json_file.write_text(m2m_json_contents) run_command(["m2mconfig", "lint", "validate", str(m2m_json_file)]) @pytest.mark.parametrize( "description, input_data, expected_err_msg", [ ( "validation should fail for invalid json file", "invalid_ data", "Failed to load file", ), ( "validation should fail for the second entry", """[ { "name": "001-machine-to-machine", "prod_aws_account": "031099521156", "qa_aws_account": "591204808501", "client_metadata": { "m2m_identity_uuid": "3398a2a2-cef9-4866-ad10-0cfe4cf5bcd7" } }, { "name": "002-machine-to-machine", "qa_aws_account": "591204808501", "client_metadata": { "m2m_identity_uuid": "3398a2a2-cef9-4866-ad10-0cfe4cf5bcd7" } } ]""", "INVALID_REGISTRY_ENTRY: entry_index=\\'1\\'", ), ], ) def test_lint_validate_failure( description: str, input_data: Any, expected_err_msg: str, testdir: Path ) -> None: """Test greetings bonjour command works.""" m2m_json_file = testdir / "m2m-bad.json" m2m_json_file.write_text(input_data) stdout, stderr = run_command( ["m2mconfig", "lint", "validate", str(m2m_json_file)], expected_returncode=1, description=description, ) assert expected_err_msg in stdout