From 000e81dcba068b0f62fce432fe0dd79e1b5deb96 Mon Sep 17 00:00:00 2001 From: wkoot <3715211+wkoot@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:18:28 +0100 Subject: [PATCH] test env var in test --- .github/workflows/docker-image.yml | 8 ++++++-- docker/docker-compose.ci.yml | 2 ++ tests/test_smoke.py | 23 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 2374b46..6f83912 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,6 +7,10 @@ on: pull_request: types: [opened, synchronize, reopened] +env: + CODE: "PROJ1" + RULES: "+csharpsquid:S104;-ts:S1561" + jobs: build: runs-on: ubuntu-latest @@ -23,7 +27,7 @@ jobs: - name: Build and run container image run: | docker build --build-arg="IMAGE_EDITION=${{ matrix.env.IMAGE_EDITION }}" -t ci . - docker run -v $(pwd)/tests:/opt/sonarqube/test -d --name ci ci + docker run -e PROJECT_CODE="${{ env.CODE }}" -e PROJECT_RULES="${{ env.RULES }}" -v $(pwd)/tests:/opt/sonarqube/test -d --name ci ci - name: Wait for Sonar instance to start # profile for language 'web' is the last; assume everything is working if we got this far @@ -37,7 +41,7 @@ jobs: docker exec -u 0:0 ci pip3 install -Ur /opt/sonarqube/test/requirements.txt - name: Run tests - run: docker exec ci python3 -m unittest -v + run: docker exec -e PROJECT_CODE="${{ env.CODE }}" -e PROJECT_RULES="${{ env.RULES }}" ci python3 -m unittest -v - name: Stop the container run: docker stop ci diff --git a/docker/docker-compose.ci.yml b/docker/docker-compose.ci.yml index f0f5e2d..9f40cc1 100644 --- a/docker/docker-compose.ci.yml +++ b/docker/docker-compose.ci.yml @@ -10,6 +10,8 @@ services: SONAR_JDBC_USERNAME: "sonar_user" SONAR_JDBC_PASSWORD: "sonar_pass" SONARQUBE_PASSWORD: "admin123" + PROJECT_CODE: "PROJ1" + PROJECT_RULES: "+csharpsquid:S104;-ts:S1561" db: environment: diff --git a/tests/test_smoke.py b/tests/test_smoke.py index c70c5d4..f80a9db 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -1,8 +1,11 @@ from os import getenv -from unittest import TestCase +from unittest import TestCase, skipUnless from sonarqube import SonarQubeClient +PROJECT_CODE = getenv("PROJECT_CODE") +PROJECT_RULES = getenv("PROJECT_RULES") + class SonarTest(TestCase): def setUp(self) -> None: @@ -15,3 +18,21 @@ def test_java_profile(self): java_quality_profiles = self.sonar_client.qualityprofiles.search_quality_profiles(language="java") java_profile_names = [profile["name"] for profile in java_quality_profiles["profiles"]] self.assertIn("Sonar way", java_profile_names) + + @skipUnless(PROJECT_CODE, "PROJECT_CODE was not passed") + def test_csharpsquid_profile(self): + search_result = self.sonar_client.qualityprofiles.search_quality_profiles( + defaults="true", language="cs", qualityProfile=f"{PROJECT_CODE}-ictu-cs-profile-v9.13.0-20231222" + ) + self.assertEqual(len(search_result['profiles']), 1) + cs_profile_key = search_result['profiles'][0]['key'] + self.assertIsNotNone(cs_profile_key) # TODO - check activated rules within profile instead + + @skipUnless(PROJECT_CODE, "PROJECT_CODE was not passed") + def test_ts_profile(self): + search_result = self.sonar_client.qualityprofiles.search_quality_profiles( + defaults="true", language="ts", qualityProfile=f"{PROJECT_CODE}-ictu-ts-profile-v10.9.0-20231222" + ) + self.assertEqual(len(search_result['profiles']), 1) + ts_profile_key = search_result['profiles'][0]['key'] + self.assertIsNotNone(ts_profile_key) # TODO - check activated rules within profile instead