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 ef72f45
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Build the Docker image
run: docker build --build-arg="IMAGE_EDITION=${{ matrix.env.IMAGE_EDITION }}" -t ci .
- 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
- name: Run the Docker image
run: docker run -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 test requirements
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 ci python3 -m unittest -v

- 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
17 changes: 17 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from os import getenv
from unittest import TestCase

from sonarqube import SonarQubeClient


class SonarTest(TestCase):
def setUp(self) -> None:
sonar_port = getenv("SONAR_PORT", "9000")
sonar_base_url = f"http://localhost:{sonar_port}"
sonar_pass = getenv("SONARQUBE_PASSWORD", "admin")
self.sonar_client = SonarQubeClient(sonarqube_url=sonar_base_url, username="admin", password=sonar_pass)

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)

0 comments on commit ef72f45

Please sign in to comment.