Skip to content

Commit

Permalink
run integration tests outside of docker
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasG0 committed Sep 18, 2024
1 parent 521e559 commit 2702538
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,16 @@ jobs:
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup git credentials"
run: "git config --global user.name 'Infrahub' && \
git config --global user.email 'infrahub@opsmill.com' && \
git config --global --add safe.directory '*' && \
git config --global credential.usehttppath true && \
git config --global credential.helper /usr/local/bin/infrahub-git-credential"
- name: "Setup Python environment"
run: "pip install toml invoke"
- name: "Set environment variables"
run: echo INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }} >> $GITHUB_ENV
- name: "Set environment variables"
run: echo INFRAHUB_IMAGE_VER=local-${{ runner.name }}-${{ github.sha }} >> $GITHUB_ENV
- name: "Clear docker environment"
run: docker compose -p $INFRAHUB_BUILD_NAME down -v --remove-orphans --rmi local
- name: "Build Test Image"
run: "invoke dev.build"
- name: "Pull External Docker Images"
run: "invoke dev.pull"
- name: "ls -l /var/run/docker.sock on host machine"
run: "ls -l /var/run/docker.sock"
- name: "Install dependencies"
run: "poetry install --no-interaction --no-ansi"
- name: "Integration Tests"
run: "invoke backend.test-integration"
- name: "Coveralls : Integration Tests"
Expand Down
16 changes: 6 additions & 10 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ async def register_core_models_schema(default_branch: Branch, register_internal_

@pytest.fixture(scope="session")
def neo4j(request: pytest.FixtureRequest) -> DockerContainer:
#if not START_DOCKER_DEPENDENCIES:
return

container = (
DockerContainer(image="neo4j:5.19.0-enterprise")
Expand All @@ -167,8 +165,6 @@ def cleanup():

@pytest.fixture(scope="session")
def rabbitmq(request: pytest.FixtureRequest) -> DockerContainer:
#if not START_DOCKER_DEPENDENCIES:
return

container = (
DockerContainer(image="rabbitmq:latest")
Expand All @@ -189,8 +185,6 @@ def cleanup():

@pytest.fixture(scope="session")
def redis(request: pytest.FixtureRequest) -> DockerContainer:
if not START_DOCKER_DEPENDENCIES:
return

container = DockerContainer(image="redis:latest").with_exposed_ports(6379)

Expand All @@ -212,9 +206,10 @@ def load_settings_before_any_test(worker_id, tmpdir_factory,
rabbitmq: DockerContainer,
redis: DockerContainer):
config.load_and_exit()
print(f"{config.SETTINGS=}")

if START_DOCKER_DEPENDENCIES:
# config.SETTINGS.database.port = neo4j.get_exposed_port(7687)
config.SETTINGS.database.port = neo4j.get_exposed_port(7687)
config.SETTINGS.broker.port = rabbitmq.get_exposed_port(5672)
config.SETTINGS.cache.port = redis.get_exposed_port(6379)

Expand All @@ -227,14 +222,15 @@ def load_settings_before_any_test(worker_id, tmpdir_factory,
except (ValueError, IndexError):
db_id = 1

config.SETTINGS.cache.address = "localhost" if not START_DOCKER_DEPENDENCIES else "172.17.0.1"
config.SETTINGS.cache.address = "localhost"
# if not START_DOCKER_DEPENDENCIES else "172.17.0.1"

if config.SETTINGS.cache.driver == config.CacheDriver.NATS:
raise ValueError("Just making sure this path is unused during testing phase.")
config.SETTINGS.cache.address = f"{BUILD_NAME}-message-queue-{db_id}"

config.SETTINGS.database.address = f"{BUILD_NAME}-database-{db_id}"
config.SETTINGS.broker.address = f"{BUILD_NAME}-message-queue-{db_id}"
config.SETTINGS.database.address = "localhost"
config.SETTINGS.broker.address = f"localhost"
config.SETTINGS.storage.local = config.FileSystemStorageSettings(path="/opt/infrahub/storage")
else:
storage_dir = tmpdir_factory.mktemp("storage")
Expand Down
12 changes: 4 additions & 8 deletions tasks/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ def test_core(context: Context, database: str = INFRAHUB_DATABASE):

@task(optional=["database"])
def test_integration(context: Context, database: str = INFRAHUB_DATABASE):
# TODO handle database
with context.cd(ESCAPED_REPO_PATH):
compose_files_cmd = build_test_compose_files_cmd(database=database)
# Ryuk is a container mainly allowing to clean-up other containers. Not sure why it does not work within CI ("Connection refused"), disabling for now.
base_cmd = f"{get_env_vars(context)} docker compose {compose_files_cmd} -p {BUILD_NAME} run {build_test_envs()} -e TESTCONTAINERS_RYUK_DISABLED=true -v {os.getcwd()}:{os.getcwd()} -w {os.getcwd()} -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker infrahub-test"
exec_cmd = f"pytest -n {NBR_WORKERS} -v --cov=infrahub {MAIN_DIRECTORY}/tests/integration/schema_lifecycle/test_schema_update.py"
if database == "neo4j":
exec_cmd += " --neo4j"
print(f"{base_cmd} {exec_cmd}")
return execute_command(context=context, command=f"{base_cmd} {exec_cmd}")
exec_cmd = f"poetry run pytest -n {NBR_WORKERS} -v --cov=infrahub {MAIN_DIRECTORY}/tests/integration"
print(f"{exec_cmd=}")
return execute_command(context=context, command=f"{exec_cmd}")


@task
Expand Down

0 comments on commit 2702538

Please sign in to comment.