diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d130897..6e86d99 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -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 diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..45713d5 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +python-sonarqube-api >= 2.0 +requests >= 2.31 diff --git a/tests/test_smoke.py b/tests/test_smoke.py new file mode 100644 index 0000000..c70c5d4 --- /dev/null +++ b/tests/test_smoke.py @@ -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)