-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use fixtures for runtime dependencies
- Loading branch information
Showing
1 changed file
with
44 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |