Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize extends tests #2375

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EXTENDS: base.mega-linter.yml
DEFAULT_BRANCH: dev
LOG_LEVEL: DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXTENDS:
- "https://raw.githubusercontent.com/oxsecurity/megalinter/main/.automation/test/mega-linter-config-test/extension1.mega-linter.yml"
- "https://raw.githubusercontent.com/oxsecurity/megalinter/main/.automation/test/mega-linter-config-test/extension2.mega-linter.yml"
FILTER_REGEX_INCLUDE: "(base)"
SHOW_ELAPSED_TIME: true
2 changes: 1 addition & 1 deletion .github/workflows/deploy-BETA-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
run: |
TEST_KEYWORDS_TO_USE_UPPER="${{ matrix.linter }}"
TEST_KEYWORDS_TO_USE="${TEST_KEYWORDS_TO_USE_UPPER,,}"
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:beta
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e GITHUB_REF_NAME=${GITHUB_REF_NAME} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:beta
timeout-minutes: 30

##############################################
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-DEV-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ jobs:
run: |
TEST_KEYWORDS_TO_USE_UPPER="${{ matrix.linter }}"
TEST_KEYWORDS_TO_USE="${TEST_KEYWORDS_TO_USE_UPPER,,}"
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:${{ needs.prepare.outputs.tag }}
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e GITHUB_REF_NAME=${GITHUB_REF_NAME} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:${{ needs.prepare.outputs.tag }}
timeout-minutes: 30

##############################################
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-DEV.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
TEST_KEYWORDS_TO_USE=""
fi
fi
docker run $CI_ENV -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter:${{steps.image_tag.outputs.tag}}
docker run $CI_ENV -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e GITHUB_REF_NAME=${GITHUB_REF_NAME} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter:${{steps.image_tag.outputs.tag}}
timeout-minutes: 60

#####################################
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-RELEASE-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
run: |
TEST_KEYWORDS_TO_USE_UPPER="${{ matrix.linter }}"
TEST_KEYWORDS_TO_USE="${TEST_KEYWORDS_TO_USE_UPPER,,}"
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:${{ github.event.release.tag_name }}
docker run -e TEST_CASE_RUN=true -e OUTPUT_FORMAT=text -e OUTPUT_FOLDER=${GITHUB_SHA} -e OUTPUT_DETAIL=detailed -e GITHUB_SHA=${GITHUB_SHA} -e GITHUB_REF_NAME=${GITHUB_REF_NAME} -e PAT="${{secrets.PAT}}" -e TEST_KEYWORDS="${TEST_KEYWORDS_TO_USE}" -e MEGALINTER_VOLUME_ROOT="${GITHUB_WORKSPACE}" -v "/var/run/docker.sock:/var/run/docker.sock:rw" -v ${GITHUB_WORKSPACE}:/tmp/lint oxsecurity/megalinter-only-${{ matrix.linter }}:${{ github.event.release.tag_name }}
timeout-minutes: 30

##############################################
Expand Down
43 changes: 36 additions & 7 deletions megalinter/tests/test_megalinter/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@


class config_test(unittest.TestCase):
branch = os.environ.get("GITHUB_REF_NAME", "main")
test_folder = (
f"https://raw.githubusercontent.com/{ML_REPO}/"
"main/.automation/test/mega-linter-config-test/"
f"{branch}/.automation/test/mega-linter-config-test/"
)

def setUp(self):
Expand All @@ -33,7 +34,7 @@ def tearDown(self):
config.delete()

def test_remote_config_success(self):
remote_config = self.test_folder + "custom.mega-linter.yml"
remote_config = self.test_folder + "remote/custom.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
self.assertEqual("(custom)", config.get("FILTER_REGEX_INCLUDE"))
Expand All @@ -44,7 +45,10 @@ def test_remote_config_error(self):
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
except Exception as e:
self.assertIn("http", str(e))
self.assertRegex(str(e), (
"Unable to retrieve config file "
f"https://.*/\.automation/test/mega-linter-config-test/custom\.mega-linter-not-existing\.yml"
))

def test_local_config_extends_success(self):
local_config = "local.mega-linter.yml"
Expand Down Expand Up @@ -72,6 +76,8 @@ def test_local_config_extends_recurse_success(self):
+ "test"
+ os.path.sep
+ "mega-linter-config-test"
+ os.path.sep
+ "local_extends_recurse"
)
self.assertEqual("(local)", config.get("FILTER_REGEX_INCLUDE"))
self.assertEqual("false", config.get("SHOW_ELAPSED_TIME"))
Expand All @@ -95,29 +101,52 @@ def test_local_config_extends_error(self):
self.assertIn("No such file or directory", str(e))

def test_remote_config_extends_success(self):
remote_config = self.test_folder + "base.mega-linter.yml"
remote_config = self.test_folder + "remote_extends/base.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
self.assertEqual("(base)", config.get("FILTER_REGEX_INCLUDE"))
self.assertEqual("(extension2)", config.get("FILTER_REGEX_EXCLUDE"))
self.assertEqual("true", config.get("SHOW_ELAPSED_TIME"))

def test_remote_config_extends_success_2(self):
remote_config = self.test_folder + "base2.mega-linter.yml"
remote_config = self.test_folder + "remote_extends_2/base2.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
self.assertEqual("(base)", config.get("FILTER_REGEX_INCLUDE"))
self.assertEqual("(extension2)", config.get("FILTER_REGEX_EXCLUDE"))
self.assertEqual("true", config.get("SHOW_ELAPSED_TIME"))

def test_remote_config_extends_error(self):
remote_config = self.test_folder + "base-error.mega-linter.yml"
remote_config = self.test_folder + "remote_extends_error/base-error.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = remote_config
try:
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
except Exception as e:
self.assertIn("http", str(e))
self.assertRegex(str(e), (
"Unable to retrieve config file "
r"https://.*/\.automation/test/mega-linter-config-test/remote_extends_error/base-error\.mega-linter\.yml"
))

def test_local_remote_config_extends_recurse_success(self):
local_config = "local.remote.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = local_config
config.init_config(
REPO_HOME_DEFAULT
+ os.path.sep
+ ".automation"
+ os.path.sep
+ "test"
+ os.path.sep
+ "mega-linter-config-test"
+ os.path.sep
+ "local_remote_extends_recurse"
)
self.assertEqual("(base)", config.get("FILTER_REGEX_INCLUDE"))
self.assertEqual("(extension2)", config.get("FILTER_REGEX_EXCLUDE"))
self.assertEqual("true", config.get("SHOW_ELAPSED_TIME"))
self.assertEqual("dev", config.get("DEFAULT_BRANCH"))
self.assertEqual("DEBUG", config.get("LOG_LEVEL"))

def test_list_of_obj_as_env_var(self):
os.environ[
Expand Down