Skip to content

Commit

Permalink
Merge pull request #73 from fitztrev/ci
Browse files Browse the repository at this point in the history
Add integration test using Lila-docker, both locally and through CI
  • Loading branch information
kraktus authored Oct 19, 2024
2 parents 3416a96 + cceb172 commit f8fac03
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lila integration test

on:
- push
- pull_request

jobs:
lila:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
container: ubuntu:22.04
services:
bdit_lila:
image: ghcr.io/lichess-org/lila-docker:main
options: --restart=always
steps:
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
- name: Install curl
run: apt-get update && apt-get install -y curl
- name: Checkout berserk
uses: actions/checkout@v4
- name: Run tests
run: |
./integration/run-tests.sh
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -34,4 +34,4 @@ jobs:
- name: Install dependencies
run: poetry install --with dev
- name: Test
run: poetry run pytest
run: poetry run pytest tests
2 changes: 1 addition & 1 deletion .github/workflows/typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ setup: ## setup poetry env and install dependencies
poetry install --with dev

test: ## run tests with pytest
poetry run pytest
poetry run pytest tests

test_record: ## run tests with pytest and record http requests
poetry run pytest --record-mode=once
Expand Down
26 changes: 26 additions & 0 deletions integration/local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -e

integration_test() {
# BDIT = Berserk Docker Image Test, trying to reduce collision
local BDIT_IMAGE=ghcr.io/lichess-org/lila-docker:main
local BDIT_LILA=bdit_lila
local BDIT_NETWORK=bdit_lila-network
local BDIT_APP=bdit_app

cleanup_containers() {
docker rm --force $BDIT_LILA > /dev/null 2>&1 || true
docker rm --force $BDIT_APP > /dev/null 2>&1 || true
docker network rm $BDIT_NETWORK > /dev/null 2>&1 || true
}

echo "Running integration tests"
cleanup_containers

docker network create $BDIT_NETWORK
docker run --name $BDIT_LILA --network $BDIT_NETWORK -d $BDIT_IMAGE
docker run --name $BDIT_APP --network $BDIT_NETWORK -v "$(pwd)":/app -w /app $BDIT_IMAGE ./integration/run-tests.sh

cleanup_containers
echo "✅ Done"
}
integration_test
15 changes: 15 additions & 0 deletions integration/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -e

python3 -m pip install -e . --no-cache-dir

attempts=0
while [ $attempts -lt 30 ]; do
if curl -s http://bdit_lila:9663 >/dev/null; then
break
fi
echo "⌛ Waiting for lila to start..."
sleep 1
attempts=$((attempts + 1))
done

pytest integration
41 changes: 41 additions & 0 deletions integration/test_lila_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import berserk
import pytest

BASE_URL = "http://bdit_lila:9663"

@pytest.fixture(scope="module")
def client():
session = berserk.TokenSession('lip_bobby')
client = berserk.Client(
session, base_url=BASE_URL)
yield client


def test_account_get(client):
me = client.account.get()
assert me['id'] == 'bobby'


def test_account_get_email(client):
assert client.account.get_email() == 'bobby@localhost'


def test_account_get_preferences(client):
preferences = client.account.get_preferences()
assert preferences['language'] == 'en-US'
assert preferences['prefs']['animation'] == 2


def test_account_kid_mode(client):
assert client.account.get_kid_mode() == False
client.account.set_kid_mode(True)
assert client.account.get_kid_mode() == True


def test_account_upgrade_to_bot():
session = berserk.TokenSession('lip_zerogames')
client = berserk.Client(
session, base_url=BASE_URL)
assert 'title' not in client.account.get()
client.account.upgrade_to_bot()
assert client.account.get()['title'] == "BOT"

0 comments on commit f8fac03

Please sign in to comment.