Skip to content

Commit

Permalink
changed logic to create override file to avoid conflicts with Torque …
Browse files Browse the repository at this point in the history
…auto-tagging overrides

bump patch version
  • Loading branch information
alexazarh committed Sep 19, 2022
1 parent 8c33e43 commit eb4cf5c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/backend/backend_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@


class BackendSerializer:
def __init__(self, backend_config: dict, backend_handler: BaseBackendHandler, tf_file_info: FileInfo):
def __init__(self, backend_config: dict, backend_handler: BaseBackendHandler, tf_file_info: FileInfo,
sandbox_id: str):
self._backend_config = backend_config
self._backend_handler = backend_handler
self._tf_file_info = tf_file_info
self._sandbox_id = sandbox_id

def _get_override_file_path(self):
(file_without_ext, ext) = os.path.splitext(self._tf_file_info.file_name)
override_file_path = os.path.join(self._tf_file_info.file_dir, f"{file_without_ext}_override.tf")
override_file_path = os.path.join(self._tf_file_info.file_dir, f"torque_backend_{self._sandbox_id}_override.tf")
return override_file_path

def create_backend_override_file(self):
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def torqify_terraform_backend(sandbox_id: str):

updated_backend_config = backend_handler.add_uid_to_tfstate(backend_config, sandbox_id)

backend_serializer = BackendSerializer(updated_backend_config, backend_handler, tf_file_backend)
backend_serializer = BackendSerializer(updated_backend_config, backend_handler, tf_file_backend, sandbox_id)
backend_serializer.create_backend_override_file()

LoggerHelper.write_info("Successfully finish creating override file for backend files\n")
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/test_backend_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_create_backend_override_file(self):
backend_config = Mock()
backend_handler = Mock()
tf_file_info = Mock()
backend_serializer = BackendSerializer(backend_config, backend_handler, tf_file_info)
backend_serializer = BackendSerializer(backend_config, backend_handler, tf_file_info, Mock())
override_file_path = Mock()
backend_serializer._get_override_file_path = Mock(return_value=override_file_path)
m = mock_open()
Expand All @@ -31,11 +31,12 @@ def test_get_override_file_path(self):
# arrange
test_file_dir = os.path.join("/", "test1", "test2")
tf_file_info = Mock(file_name="test.tf", file_dir=test_file_dir)
backend_serializer = BackendSerializer(Mock(), Mock(), tf_file_info)
sandbox_id = Mock()
backend_serializer = BackendSerializer(Mock(), Mock(), tf_file_info, sandbox_id)

# act
result = backend_serializer._get_override_file_path()

# assert
self.assertEqual(result, os.path.join(test_file_dir, "test_override.tf"))
self.assertEqual(result, os.path.join(test_file_dir, f"torque_backend_{sandbox_id}_override.tf"))
1
2 changes: 1 addition & 1 deletion tests/unit_tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_torqify_terraform_backend_with_s3_backend(self, backend_serializer_clas
update_backend_config = {'s3': {'bucket': 'my-bucket',
'key': 'path/to/my/key' + "-" + str(sandbox_id),
'region': 'us-west-2'}}
backend_serializer_class_mock.assert_called_once_with(update_backend_config, ANY, ANY)
backend_serializer_class_mock.assert_called_once_with(update_backend_config, ANY, ANY, sandbox_id)
self.assertIsInstance(backend_serializer_class_mock.call_args[0][1], S3BackendHandler)
self.assertIsInstance(backend_serializer_class_mock.call_args[0][2], FileInfo)
backend_serializer_class_mock.return_value.create_backend_override_file.assert_called_once()
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2

0 comments on commit eb4cf5c

Please sign in to comment.