Skip to content

Commit

Permalink
Improve config test (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdovaz authored Mar 6, 2023
1 parent 61a5af9 commit cc683d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 3 additions & 4 deletions megalinter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def init_config(workspace=None):
if "EXTENDS" in runtime_config:
combined_config = {}
CONFIG_SOURCE = combine_config(
workspace, config_file, runtime_config, combined_config, CONFIG_SOURCE
workspace, runtime_config, combined_config, CONFIG_SOURCE
)
runtime_config = combined_config
# Print & set config in cache
print(f"[config] {CONFIG_SOURCE}")
set_config(runtime_config)


def combine_config(workspace, config_file, config, combined_config, config_source):
def combine_config(workspace, config, combined_config, config_source):
extends = config["EXTENDS"]
if isinstance(extends, str):
extends = extends.split(",")
Expand All @@ -91,7 +91,7 @@ def combine_config(workspace, config_file, config, combined_config, config_sourc
r = requests.get(extends_item, allow_redirects=True)
assert (
r.status_code == 200
), f"Unable to retrieve EXTENDS config file {config_file}"
), f"Unable to retrieve EXTENDS config file {extends_item}"
extends_config_data = yaml.safe_load(r.content)
else:
with open(
Expand All @@ -103,7 +103,6 @@ def combine_config(workspace, config_file, config, combined_config, config_sourc
if "EXTENDS" in extends_config_data:
combine_config(
workspace,
extends_item,
extends_config_data,
combined_config,
config_source,
Expand Down
9 changes: 8 additions & 1 deletion megalinter/tests/test_megalinter/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ def test_remote_config_extends_error(self):
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
except Exception as e:
self.assertIn("Unable to retrieve EXTENDS config file", str(e)),
self.assertRegex(
str(e),
(
"Unable to retrieve EXTENDS config file "
r"https://.*/\.automation/test/mega-linter-config-test/"
r"extension3\.mega-linter\.yml"
),
)
finally:
self.restore_branch_in_input_files(changed_files)

Expand Down

0 comments on commit cc683d0

Please sign in to comment.