Skip to content

Commit

Permalink
we read config files from absolute paths now, so adjust the mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed Sep 21, 2024
1 parent 15de707 commit a65dd97
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/test_modules/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import namedtuple
from pathlib import PosixPath
from unittest import mock
from unittest.mock import Mock, MagicMock, PropertyMock

Expand Down Expand Up @@ -189,19 +190,24 @@ def test_get_layer_profile(muted_click_context):
"""

data_dict = {
"config.tf": FILE_CONFIG_TF,
"locals.tf": FILE_LOCALS_TF,
"~/config/backend.tfvars": FILE_BACKEND_TFVARS,
"~/.aws/test/config": FILE_AWS_CONFIG,
"~/.aws/test/credentials": FILE_AWS_CREDENTIALS,
}


def open_side_effect(name, *args, **kwargs):
def open_side_effect(name: PosixPath, *args, **kwargs):
"""
Everytime we call open(), this side effect will try to get the value from data_dict rather than reading a disk file.
"""
return mock.mock_open(read_data=data_dict[name])()
if str(name).endswith("config.tf"):
read_data = FILE_CONFIG_TF
elif str(name).endswith("locals.tf"):
read_data = FILE_LOCALS_TF
else:
read_data = data_dict[name]

return mock.mock_open(read_data=read_data)()


b3_client = Mock()
Expand Down

0 comments on commit a65dd97

Please sign in to comment.