-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from fitztrev/ci
Add integration test using Lila-docker, both locally and through CI
- Loading branch information
Showing
7 changed files
with
119 additions
and
4 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 |
---|---|---|
@@ -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 |
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
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
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
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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" |