Skip to content

Commit db5cdc2

Browse files
authored
PYSCAN-62 Run integration tests in CI (#50)
1 parent 297227e commit db5cdc2

File tree

5 files changed

+103
-65
lines changed

5 files changed

+103
-65
lines changed

.cirrus.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ env:
88
SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
99
SONAR_HOST_URL: https://sonarcloud.io
1010
DEPLOY_PULL_REQUEST: 'true'
11-
POETRY_VIRTUALENVS_PATH: ".cache/poetry/venvs"
12-
POETRY_CACHE_DIR: ".cache/poetry/pypoetry"
11+
POETRY_VIRTUALENVS_PATH: "~/.cache/poetry/venvs"
12+
POETRY_CACHE_DIR: "~/.cache/poetry/pypoetry"
1313

1414
only_if: $CIRRUS_USER_COLLABORATOR == "true" && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == $CIRRUS_DEFAULT_BRANCH || $CIRRUS_BRANCH =~ "feature/*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")
1515

@@ -30,8 +30,8 @@ container_definition: &CONTAINER_DEFINITION
3030

3131
poetry_cache_template: &POETRY_CACHE
3232
poetry_cache:
33-
folder: .cache/poetry/
34-
fingerprint_script: cat poetry.lock
33+
folder: ~/.cache/poetry/
34+
fingerprint_script: cat poetry.lock its/poetry.lock
3535

3636
.poetry_template: &POETRY_TEMPLATE
3737
eks_container:
@@ -124,12 +124,34 @@ build_task:
124124
name: "Build"
125125
build_script: regular_poetry_build_publish
126126

127+
its_task:
128+
name: "Integration Tests"
129+
alias: its
130+
sonarqube_cache:
131+
folder: sonarqube_cache/
132+
populate_script: mkdir -p sonarqube_cache && wget -q https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.5.1.90531.zip -O sonarqube_cache/sonarqube.zip
133+
fingerprint_key: sonarqube-10.5.1.90531
134+
<<: *POETRY_TEMPLATE
135+
its_script:
136+
- unzip -q sonarqube_cache/sonarqube.zip -d sonarqube
137+
- cd $(ls -d sonarqube/*/)
138+
- ./bin/linux-x86-64/sonar.sh start
139+
- cd -
140+
- cd its/
141+
- jfrog poetry-config --server-id-resolve repox --repo-resolve sonarsource-pypi
142+
- jfrog poetry install
143+
- unset SONAR_TOKEN
144+
- unset SONARCLOUD_ANALYSIS
145+
- unset SONAR_HOST_URL
146+
- poetry run pytest
147+
127148
promote_task:
128149
depends_on:
129150
- formatting
130151
- analysis
131152
- qa
132153
- build
154+
- its
133155
env:
134156
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
135157
GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]

its/compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
22
sonarqube:
3-
image: sonarqube:10.3-community
43
ports:
54
- "9000:9000"
5+
image: sonarqube:10.5.1-community

its/poetry.lock

Lines changed: 44 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

its/pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ requests = "2.31.0"
4343
pysonar = { "path" = "../" }
4444

4545
[[tool.poetry.source]]
46-
name = "repox"
47-
url = "https://repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi/simple/"
48-
priority = "default"
46+
name = 'jfrog-server'
47+
url = 'https://repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi/simple'
4948

5049
[[tool.poetry.source]]
5150
name = "PyPI"

its/tests/conftest.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,33 @@ def check_health(sonarqube_client: SonarQubeClient) -> bool:
3838
return False
3939

4040

41-
@pytest.fixture(scope="session")
42-
def sonarqube_client(docker_ip, docker_services) -> SonarQubeClient:
43-
"""Ensure that sonarqube service is up and responsive."""
44-
port = docker_services.port_for("sonarqube", 9000)
45-
url = f"http://{docker_ip}:{port}"
46-
sonarqube_client = SonarQubeClient(url)
47-
docker_services.wait_until_responsive(
48-
timeout=120.0, pause=5, check=lambda: check_health(sonarqube_client)
49-
)
50-
response = sonarqube_client.get_system_status()
51-
assert response.status_code == 200
52-
status = response.json()["status"]
53-
assert status == "UP"
54-
return sonarqube_client
41+
if "CIRRUS_OS" in os.environ:
42+
from time import sleep
43+
@pytest.fixture(scope="session")
44+
def sonarqube_client() -> SonarQubeClient:
45+
"""Ensure that sonarqube service is up and responsive."""
46+
url = "http://localhost:9000"
47+
sonarqube_client = SonarQubeClient(url)
48+
while not check_health(sonarqube_client):
49+
print("Waiting for SonarQube to be up")
50+
sleep(10)
51+
response = sonarqube_client.get_system_status()
52+
assert response.status_code == 200
53+
status = response.json()["status"]
54+
assert status == "UP"
55+
return sonarqube_client
56+
else:
57+
@pytest.fixture(scope="session")
58+
def sonarqube_client(docker_ip, docker_services) -> SonarQubeClient:
59+
"""Ensure that sonarqube service is up and responsive."""
60+
port = docker_services.port_for("sonarqube", 9000)
61+
url = f"http://{docker_ip}:{port}"
62+
sonarqube_client = SonarQubeClient(url)
63+
docker_services.wait_until_responsive(
64+
timeout=120.0, pause=5, check=lambda: check_health(sonarqube_client)
65+
)
66+
response = sonarqube_client.get_system_status()
67+
assert response.status_code == 200
68+
status = response.json()["status"]
69+
assert status == "UP"
70+
return sonarqube_client

0 commit comments

Comments
 (0)