Skip to content

Commit

Permalink
Set up python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wkoot committed Feb 13, 2024
1 parent b8a8448 commit 38038f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build the Docker image
- name: Build the container image
run: docker build --build-arg="IMAGE_EDITION=${{ matrix.env.IMAGE_EDITION }}" -t ci .

- name: Run the Docker image
run: docker run -d --name ci ci
- name: Run the container with tests volume
run: docker run -v $(pwd)/tests:/tests -d --name ci ci

- name: Verify the Docker image
- name: Wait for Sonar instance to start
# profile for language 'web' is the last; assume everything is working if we got this far
run: docker logs -f ci |& sed "/Current profile for language 'web' is 'Sonar way'/ q"
timeout-minutes: 3

- name: Stop the Docker image
- name: Install python and pip packages
run: |
docker exec -u 0:0 ci apt-get update
docker exec -u 0:0 ci apt-get install -y python3 python3-pip
docker exec -u 0:0 ci pip3 install -Ur /tests/requirements.txt
- name: Run tests
run: docker exec -u 0:0 ci python3 /tests/test.py

- name: Stop the container
run: docker stop ci
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-sonarqube-api >= 2.0
requests >= 2.31
13 changes: 13 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from os import getenv

from sonarqube import SonarQubeClient

sonar_port = getenv("SONAR_PORT", "9000")
sonar_base_url = f"http://localhost:{sonar_port}"
login_credentials = {'login': 'admin', 'password': 'admin123'}

sonar = SonarQubeClient(sonarqube_url=sonar_base_url, username='admin', password='admin123')
java_quality_profiles = sonar.qualityprofiles.search_quality_profiles(language="java")
java_profile_names = [profile['name'] for profile in java_quality_profiles['profiles']]

assert "Sonar way" in java_profile_names

0 comments on commit 38038f7

Please sign in to comment.