Skip to content

Commit

Permalink
feat(STATE,FILESYSTEM): apply v1 job spec schema
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Jun 8, 2021
1 parent c337ff8 commit b8bb14c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mac_maker/utilities/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ def get_profile_data_path(self) -> Path:
def get_roles_path(self) -> Path:
"""Returns the current Ansible roles folder location(s)."""
return self.get_profile_data_path() / "roles"

@convertable_path
def get_collections_path(self) -> Path:
"""Returns the current Ansible collections folder location(s)."""
return self.get_profile_data_path() / "collections"
1 change: 1 addition & 0 deletions mac_maker/utilities/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def state_generate(self, filesystem: FileSystem):
"playbook":
filesystem.get_playbook_file(string=True),
"roles_path": [filesystem.get_roles_path(string=True)],
"collections_path": [filesystem.get_collections_path(string=True)],
"inventory":
filesystem.get_inventory_file(string=True),
}
Expand Down
15 changes: 15 additions & 0 deletions mac_maker/utilities/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,18 @@ def test_get_roles_path_str(self):
self.filesystem.get_roles_path(string=True),
str((self.mock_root / config.PROFILE_FOLDER_PATH / "roles").resolve())
)

def test_get_collections_path(self):
self.assertEqual(
self.filesystem.get_collections_path(),
self.mock_root / config.PROFILE_FOLDER_PATH / "collections"
)

def test_get_collections_path_str(self):
self.assertEqual(
self.filesystem.get_collections_path(string=True),
str(
(self.mock_root / config.PROFILE_FOLDER_PATH /
"collections").resolve()
)
)
17 changes: 16 additions & 1 deletion mac_maker/utilities/tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Test the State class."""

import json
import os
from io import StringIO
from logging import Logger
from pathlib import Path
from unittest import TestCase, mock

from .. import state
from jsonschema import validate
from .. import filesystem, state

STATE_MODULE = state.__name__

Expand All @@ -21,12 +23,25 @@ def setUp(self):
}
self.mock_state_file_name = Path("spec.json")

self.schema_definition = (
Path(os.path.dirname(__file__)).parent.parent / "schemas" /
"job_v1.json"
)

def test_init_settings(self):
self.assertIsInstance(
self.state.log,
Logger,
)

def test_state_generation_conforms_to_spec(self):
with open(self.schema_definition) as fhandle:
schema = json.load(fhandle)

mock_fs = filesystem.FileSystem("/root/mockdir")
generated_state = self.state.state_generate(mock_fs)
validate(generated_state, schema)

@mock.patch('builtins.open')
def test_state_dehydrate(self, m_open):

Expand Down

0 comments on commit b8bb14c

Please sign in to comment.