Skip to content

Commit

Permalink
feat(JOBS): precheck notes only when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Feb 16, 2022
1 parent 5a9fbd1 commit 83914d8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mac_maker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def apply_from_github(github_url: str, branch: Optional[str]) -> None:
GITHUB_URL: URL of a GitHub repo containing a machine profile definition.
"""
job = jobs.GitHubJob(github_url, branch)
job.precheck()
job.precheck(notes=False)
job.provision()


Expand All @@ -85,7 +85,7 @@ def apply_from_spec(spec_file: str) -> None:
SPEC_FILE: The location of a spec.json file.
"""
job = jobs.FileSystemJob(spec_file)
job.precheck()
job.precheck(notes=False)
job.provision()


Expand Down
5 changes: 3 additions & 2 deletions mac_maker/jobs/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_state(self) -> TypeState:
"""Assemble and return a state object."""
raise NotImplementedError # nocover

def precheck(self) -> None:
def precheck(self, notes: bool = True) -> None:
"""Precheck the profile for validity and environment variable content."""

precheck_data = self.get_precheck_content()
Expand All @@ -52,7 +52,8 @@ def precheck(self) -> None:
click.echo(violation)
sys.exit(1)

click.echo(precheck_data['notes'])
if notes:
click.echo(precheck_data['notes'])

def provision(self) -> None:
"""Begin provisioning the local machine."""
Expand Down
14 changes: 14 additions & 0 deletions mac_maker/jobs/tests/test_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def test_precheck_echo(self, m_echo: mock.Mock, m_env: mock.Mock) -> None:
self.concrete_job.mock_precheck_content['notes']
)

def test_precheck_echo_no_notes(
self, m_echo: mock.Mock, m_env: mock.Mock
) -> None:

instance = m_env.return_value
instance.validate_environment.return_value = {
'is_valid': True,
'violations': [],
}

self.concrete_job.precheck(notes=False)

m_echo.assert_not_called()

def test_precheck_config_invalid(
self,
_: mock.Mock,
Expand Down
4 changes: 2 additions & 2 deletions mac_maker/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_apply(self, m_job: mock.Mock) -> None:
)

m_job.assert_called_once_with(self.repository_http_url, self.branch)
instance.precheck.assert_called_once_with()
instance.precheck.assert_called_once_with(notes=False)
instance.provision.assert_called_once_with()


Expand All @@ -111,7 +111,7 @@ def test_apply(self, m_job: mock.Mock) -> None:
args=f"apply spec {mock_spec_file}",
)
m_job.assert_called_once_with(mock_spec_file)
instance.precheck.assert_called_once_with()
instance.precheck.assert_called_once_with(notes=False)
instance.provision.assert_called_once_with()


Expand Down

0 comments on commit 83914d8

Please sign in to comment.