Skip to content

Commit

Permalink
test env var in test
Browse files Browse the repository at this point in the history
  • Loading branch information
wkoot committed Feb 15, 2024
1 parent ac5bd85 commit 000e81d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions docker/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 22 additions & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

0 comments on commit 000e81d

Please sign in to comment.