Skip to content

Commit

Permalink
test: use fixtures for runtime dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
2mal3 committed Feb 22, 2025
1 parent 1c69b04 commit 4bc798e
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions tests/test_logic/test_main.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
import asyncio

import podman
import pytest
from podman.domain.containers import Container

from somnus.logic import start
from somnus.logic import start, stop
from somnus.config import Config


@pytest.fixture(scope="session", autouse=True)
def podman_setup():
client = podman.PodmanClient()

container: Container = client.containers.run(
"somnus-test", detach=True, ports={"22/tcp": 25566, "25565/tcp": 25565}
) # type: ignore
if not client.ping():
raise Exception("Podman service is not running")
container.wait(condition="running")

yield

#container.stop()
#container.remove()

client.close()


def test_main():
with podman.PodmanClient() as client:
if not client.ping():
raise Exception("Podman service is not running")

container: Container = client.containers.run(
"somnus-test", detach=True, ports={"22/tcp": 25566, "25565/tcp": 25565}
)
container.wait(condition="running")

asyncio.run(run_server())

container.stop()
container.remove()


async def run_server():
async for _ in start.start_server(
Config(
DISCORD_TOKEN="",
HOST_SERVER_HOST="localhost",
HOST_SERVER_SSH_PORT=25566,
HOST_SERVER_USER="root",
HOST_SERVER_PASSWORD="root",
MC_SERVER_START_CMD="./start.sh",
MC_SERVER_ADDRESS="25565",
DISCORD_SUPER_USER_ID="",
DEBUG=True,
)
):
config = Config(
DISCORD_TOKEN="",
HOST_SERVER_HOST="localhost",
HOST_SERVER_SSH_PORT=25566,
HOST_SERVER_USER="root",
HOST_SERVER_PASSWORD="root",
MC_SERVER_START_CMD="./start.sh",
MC_SERVER_ADDRESS="25565",
DISCORD_SUPER_USER_ID="",
DEBUG=True,
)

asyncio.run(start_server(config))
asyncio.run(stop_server(config))


async def start_server(config: Config):
async for _ in start.start_server(config):
pass


async def stop_server(config: Config):
async for _ in stop.stop_server(True, config):
pass

0 comments on commit 4bc798e

Please sign in to comment.