From d3f4293e1482c65fc89260dce54d1323493528c0 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Thu, 29 Feb 2024 00:33:57 -0500 Subject: [PATCH 01/18] Add lila github action --- .github/workflows/lila.yml | 60 ++++++++++++++++++++++++++++++++++++++ integration/sample.py | 14 +++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/lila.yml create mode 100644 integration/sample.py diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml new file mode 100644 index 0000000..3685e66 --- /dev/null +++ b/.github/workflows/lila.yml @@ -0,0 +1,60 @@ +name: lila integration test + +on: + - push + - pull_request + +jobs: + lila: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + container: ubuntu:22.04 + services: + lila: + image: ghcr.io/lichess-org/lila-docker:ci + options: --restart=always + ports: + - 9663:9663 + env: + MONGO_URL: mongodb://mongodb?appName=lila + REDIS_URL: redis://redis + mongodb: + image: mongo:5.0-focal + redis: + image: redis:7-alpine + steps: + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + - 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 pymongo requests + - name: Checkout lila-db-seed + uses: actions/checkout@v4 + with: + repository: lichess-org/lila-db-seed + - name: Seed database + run: | + ./spamdb/spamdb.py \ + --uri=mongodb://mongodb/lichess \ + --drop-db \ + --password=password \ + --su-password=password \ + --streamers \ + --coaches \ + --tokens + - name: Checkout berserk + uses: actions/checkout@v4 + - name: Install berserk + run: python -m pip install -e . + - name: Run tests + run: | + python integration/sample.py diff --git a/integration/sample.py b/integration/sample.py new file mode 100644 index 0000000..7e335cf --- /dev/null +++ b/integration/sample.py @@ -0,0 +1,14 @@ +import berserk + +session = berserk.TokenSession('lip_bobby') +client = berserk.Client(session, base_url="http://lila:9663") + +me = client.account.get() +assert me['id'] == 'bobby' + +email = client.account.get_email() +assert email == 'bobby@localhost' + +assert client.account.get_kid_mode() == False +client.account.set_kid_mode(True) +assert client.account.get_kid_mode() == True From cdca866bc2e2415380c5b09c5247fd729fef5194 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Thu, 29 Feb 2024 11:23:50 -0500 Subject: [PATCH 02/18] exposing port not necessary --- .github/workflows/lila.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index 3685e66..577830c 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -1,4 +1,4 @@ -name: lila integration test +name: Lila integration test on: - push @@ -15,8 +15,6 @@ jobs: lila: image: ghcr.io/lichess-org/lila-docker:ci options: --restart=always - ports: - - 9663:9663 env: MONGO_URL: mongodb://mongodb?appName=lila REDIS_URL: redis://redis From e8a7526606a81faad4ff639d934963368a36a4dc Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 15:05:11 -0500 Subject: [PATCH 03/18] Ability to run locally (#1) --- .github/workflows/lila.yml | 39 +++++------------------------------- .github/workflows/test.yml | 2 +- .github/workflows/typing.yml | 2 +- integration/run.sh | 15 ++++++++++++++ integration/sample.py | 3 +-- integration/test | 22 ++++++++++++++++++++ 6 files changed, 45 insertions(+), 38 deletions(-) create mode 100755 integration/run.sh create mode 100755 integration/test diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index 577830c..197dfdf 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -9,50 +9,21 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] container: ubuntu:22.04 services: lila: - image: ghcr.io/lichess-org/lila-docker:ci + image: ghcr.io/lichess-org/lila-docker:ci2 options: --restart=always - env: - MONGO_URL: mongodb://mongodb?appName=lila - REDIS_URL: redis://redis - mongodb: - image: mongo:5.0-focal - redis: - image: redis:7-alpine steps: - - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 21 - 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 pymongo requests - - name: Checkout lila-db-seed - uses: actions/checkout@v4 - with: - repository: lichess-org/lila-db-seed - - name: Seed database - run: | - ./spamdb/spamdb.py \ - --uri=mongodb://mongodb/lichess \ - --drop-db \ - --password=password \ - --su-password=password \ - --streamers \ - --coaches \ - --tokens + - name: Install curl + run: apt-get update && apt-get install -y curl - name: Checkout berserk uses: actions/checkout@v4 - - name: Install berserk - run: python -m pip install -e . - name: Run tests run: | - python integration/sample.py + ./integration/run.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f16cee2..58cb035 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/.github/workflows/typing.yml b/.github/workflows/typing.yml index 83f8131..629ca2f 100644 --- a/.github/workflows/typing.yml +++ b/.github/workflows/typing.yml @@ -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 diff --git a/integration/run.sh b/integration/run.sh new file mode 100755 index 0000000..aed15a1 --- /dev/null +++ b/integration/run.sh @@ -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://lila:9663 >/dev/null; then + break + fi + echo "⌛ Waiting for lila to start..." + sleep 1 + attempts=$((attempts + 1)) +done + +python3 integration/sample.py diff --git a/integration/sample.py b/integration/sample.py index 7e335cf..0f2af38 100644 --- a/integration/sample.py +++ b/integration/sample.py @@ -6,8 +6,7 @@ me = client.account.get() assert me['id'] == 'bobby' -email = client.account.get_email() -assert email == 'bobby@localhost' +assert client.account.get_email() == 'bobby@localhost' assert client.account.get_kid_mode() == False client.account.set_kid_mode(True) diff --git a/integration/test b/integration/test new file mode 100755 index 0000000..7951937 --- /dev/null +++ b/integration/test @@ -0,0 +1,22 @@ +#!/bin/bash -e + +IMAGE=ghcr.io/lichess-org/lila-docker:ci2 + +cleanup_containers() { + docker rm --force lila > /dev/null 2>&1 || true + docker rm --force app > /dev/null 2>&1 || true + docker network rm lila-network > /dev/null 2>&1 || true +} + +echo "Running integration tests" + +cleanup_containers +docker network create lila-network || true +docker run -d --name lila --network lila-network $IMAGE + +docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE sh -c "./integration/run.sh" + +echo "✅ Integration tests passed" + +cleanup_containers +echo "✅ Done" From 9d330c80727cc6e9b124ece1a3e5b5efc7745e52 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 15:17:48 -0500 Subject: [PATCH 04/18] update ci image --- .github/workflows/lila.yml | 2 +- integration/test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index 197dfdf..e212028 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -13,7 +13,7 @@ jobs: container: ubuntu:22.04 services: lila: - image: ghcr.io/lichess-org/lila-docker:ci2 + image: ghcr.io/lichess-org/lila-docker:ci options: --restart=always steps: - name: Setup Python ${{ matrix.python-version }} diff --git a/integration/test b/integration/test index 7951937..522fe07 100755 --- a/integration/test +++ b/integration/test @@ -1,6 +1,6 @@ #!/bin/bash -e -IMAGE=ghcr.io/lichess-org/lila-docker:ci2 +IMAGE=ghcr.io/lichess-org/lila-docker:ci cleanup_containers() { docker rm --force lila > /dev/null 2>&1 || true From 8f39bab33c8d04a099cde2b90ee8eef0626abc7c Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:01:20 -0500 Subject: [PATCH 05/18] sample tests --- integration/sample.py | 13 ------------- integration/test_account.py | 24 ++++++++++++++++++++++++ integration/test_users.py | 8 ++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) delete mode 100644 integration/sample.py create mode 100644 integration/test_account.py create mode 100644 integration/test_users.py diff --git a/integration/sample.py b/integration/sample.py deleted file mode 100644 index 0f2af38..0000000 --- a/integration/sample.py +++ /dev/null @@ -1,13 +0,0 @@ -import berserk - -session = berserk.TokenSession('lip_bobby') -client = berserk.Client(session, base_url="http://lila:9663") - -me = client.account.get() -assert me['id'] == 'bobby' - -assert client.account.get_email() == 'bobby@localhost' - -assert client.account.get_kid_mode() == False -client.account.set_kid_mode(True) -assert client.account.get_kid_mode() == True diff --git a/integration/test_account.py b/integration/test_account.py new file mode 100644 index 0000000..6b25941 --- /dev/null +++ b/integration/test_account.py @@ -0,0 +1,24 @@ +import berserk + +def test_account_get(): + session = berserk.TokenSession('lip_bobby') + client = berserk.Client(session, base_url="http://lila:9663") + + me = client.account.get() + assert me['id'] == 'bobby' + + +def test_account_get_email(): + session = berserk.TokenSession('lip_bobby') + client = berserk.Client(session, base_url="http://lila:9663") + + assert client.account.get_email() == 'bobby@localhost' + + +def test_account_get_set_kid_mode(): + session = berserk.TokenSession('lip_bobby') + client = berserk.Client(session, base_url="http://lila:9663") + + assert client.account.get_kid_mode() == False + client.account.set_kid_mode(True) + assert client.account.get_kid_mode() == True diff --git a/integration/test_users.py b/integration/test_users.py new file mode 100644 index 0000000..27b17f8 --- /dev/null +++ b/integration/test_users.py @@ -0,0 +1,8 @@ +import berserk + +def test_account_get(): + client = berserk.Client(base_url="http://lila:9663") + + top_10 = client.users.get_all_top_10() + + assert len(top_10['bullet']) == 10 From aefea7eab10edc383f2f577ec3270ab15820fd66 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:10:36 -0500 Subject: [PATCH 06/18] use pytest --- integration/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/run.sh b/integration/run.sh index aed15a1..4ac2fb0 100755 --- a/integration/run.sh +++ b/integration/run.sh @@ -12,4 +12,4 @@ while [ $attempts -lt 30 ]; do attempts=$((attempts + 1)) done -python3 integration/sample.py +pytest integration From 98d43fd9432d096e68981e9c636e91fef1214b8c Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:14:07 -0500 Subject: [PATCH 07/18] install pytest --- .github/workflows/lila.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index e212028..b441231 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -20,6 +20,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest - name: Install curl run: apt-get update && apt-get install -y curl - name: Checkout berserk From b16fbea9536af40eab5aff9764aa80620e6ee668 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:18:58 -0500 Subject: [PATCH 08/18] fix install pytest --- .github/workflows/lila.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index b441231..6e9e9bc 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -23,7 +23,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest + python -m pip install pytest - name: Install curl run: apt-get update && apt-get install -y curl - name: Checkout berserk From 571a881947fe6d66dbbd4b5800a14b489e57726c Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:28:16 -0500 Subject: [PATCH 09/18] cleanup --- integration/{test => local} | 4 +--- integration/{run.sh => run-tests.sh} | 0 integration/{test_account.py => test_lila_account.py} | 0 integration/{test_users.py => test_lila_users.py} | 0 4 files changed, 1 insertion(+), 3 deletions(-) rename integration/{test => local} (86%) rename integration/{run.sh => run-tests.sh} (100%) rename integration/{test_account.py => test_lila_account.py} (100%) rename integration/{test_users.py => test_lila_users.py} (100%) diff --git a/integration/test b/integration/local similarity index 86% rename from integration/test rename to integration/local index 522fe07..498c9c4 100755 --- a/integration/test +++ b/integration/local @@ -14,9 +14,7 @@ cleanup_containers docker network create lila-network || true docker run -d --name lila --network lila-network $IMAGE -docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE sh -c "./integration/run.sh" - -echo "✅ Integration tests passed" +docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE sh -c "./integration/run-tests.sh" cleanup_containers echo "✅ Done" diff --git a/integration/run.sh b/integration/run-tests.sh similarity index 100% rename from integration/run.sh rename to integration/run-tests.sh diff --git a/integration/test_account.py b/integration/test_lila_account.py similarity index 100% rename from integration/test_account.py rename to integration/test_lila_account.py diff --git a/integration/test_users.py b/integration/test_lila_users.py similarity index 100% rename from integration/test_users.py rename to integration/test_lila_users.py From af04989db4d02fe53a6064a811fd01bd7c6009df Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:33:03 -0500 Subject: [PATCH 10/18] update script name on gh action --- .github/workflows/lila.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index 6e9e9bc..7c50bf8 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -30,4 +30,4 @@ jobs: uses: actions/checkout@v4 - name: Run tests run: | - ./integration/run.sh + ./integration/run-tests.sh From 62ef7bee16f44562fc131bf319f435a8c0442b7d Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 2 Mar 2024 16:49:15 -0500 Subject: [PATCH 11/18] `test` action to only run the `/tests/` folder tests --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58cb035..569f884 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,4 +34,4 @@ jobs: - name: Install dependencies run: poetry install --with dev - name: Test - run: poetry run pytest + run: poetry run pytest tests From 74aee31601539ad23cc918b265689a741c45b11d Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sun, 3 Mar 2024 07:34:16 -0500 Subject: [PATCH 12/18] cleanup shell script --- integration/local | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integration/local b/integration/local index 498c9c4..2f3ac93 100755 --- a/integration/local +++ b/integration/local @@ -9,12 +9,11 @@ cleanup_containers() { } echo "Running integration tests" - cleanup_containers -docker network create lila-network || true -docker run -d --name lila --network lila-network $IMAGE -docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE sh -c "./integration/run-tests.sh" +docker network create lila-network +docker run --name lila --network lila-network -d $IMAGE +docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE ./integration/run-tests.sh cleanup_containers echo "✅ Done" From d72f900500f48acfce8d091269c5d2d8b198544f Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Fri, 8 Mar 2024 22:42:15 -0500 Subject: [PATCH 13/18] cleanup tests --- integration/test_lila_account.py | 17 ++++++++--------- integration/test_lila_users.py | 8 ++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/integration/test_lila_account.py b/integration/test_lila_account.py index 6b25941..eaf4b66 100644 --- a/integration/test_lila_account.py +++ b/integration/test_lila_account.py @@ -1,24 +1,23 @@ import berserk +import pytest -def test_account_get(): +@pytest.fixture(scope="module") +def client(): session = berserk.TokenSession('lip_bobby') client = berserk.Client(session, base_url="http://lila:9663") + yield client + +def test_account_get(client): me = client.account.get() assert me['id'] == 'bobby' -def test_account_get_email(): - session = berserk.TokenSession('lip_bobby') - client = berserk.Client(session, base_url="http://lila:9663") - +def test_account_get_email(client): assert client.account.get_email() == 'bobby@localhost' -def test_account_get_set_kid_mode(): - session = berserk.TokenSession('lip_bobby') - client = berserk.Client(session, base_url="http://lila:9663") - +def test_update_kid_mode(client): assert client.account.get_kid_mode() == False client.account.set_kid_mode(True) assert client.account.get_kid_mode() == True diff --git a/integration/test_lila_users.py b/integration/test_lila_users.py index 27b17f8..8d1d127 100644 --- a/integration/test_lila_users.py +++ b/integration/test_lila_users.py @@ -1,8 +1,12 @@ import berserk +import pytest -def test_account_get(): +@pytest.fixture(scope="module") +def client(): client = berserk.Client(base_url="http://lila:9663") + yield client + +def test_account_get(client): top_10 = client.users.get_all_top_10() - assert len(top_10['bullet']) == 10 From 611688ad42712464a0a2e4153c87d17e3d12f5c2 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sat, 9 Mar 2024 00:09:34 -0500 Subject: [PATCH 14/18] test upgrading bot account --- integration/test_lila_account.py | 21 +++++++++++++++++++-- integration/test_lila_users.py | 12 ------------ 2 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 integration/test_lila_users.py diff --git a/integration/test_lila_account.py b/integration/test_lila_account.py index eaf4b66..66c59fb 100644 --- a/integration/test_lila_account.py +++ b/integration/test_lila_account.py @@ -1,10 +1,12 @@ import berserk import pytest + @pytest.fixture(scope="module") def client(): session = berserk.TokenSession('lip_bobby') - client = berserk.Client(session, base_url="http://lila:9663") + client = berserk.Client( + session, base_url="http://lila:9663") yield client @@ -17,7 +19,22 @@ def test_account_get_email(client): assert client.account.get_email() == 'bobby@localhost' -def test_update_kid_mode(client): +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="http://lila:9663") + assert 'title' not in client.account.get() + client.account.upgrade_to_bot() + assert client.account.get()['title'] == "BOT" diff --git a/integration/test_lila_users.py b/integration/test_lila_users.py deleted file mode 100644 index 8d1d127..0000000 --- a/integration/test_lila_users.py +++ /dev/null @@ -1,12 +0,0 @@ -import berserk -import pytest - -@pytest.fixture(scope="module") -def client(): - client = berserk.Client(base_url="http://lila:9663") - yield client - - -def test_account_get(client): - top_10 = client.users.get_all_top_10() - assert len(top_10['bullet']) == 10 From 69f8088a794482f684829840ede8430fad96bf77 Mon Sep 17 00:00:00 2001 From: Trevor Fitzgerald Date: Sun, 31 Mar 2024 00:05:18 -0400 Subject: [PATCH 15/18] update ci image version --- .github/workflows/lila.yml | 2 +- integration/local | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lila.yml b/.github/workflows/lila.yml index 7c50bf8..535d390 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/lila.yml @@ -13,7 +13,7 @@ jobs: container: ubuntu:22.04 services: lila: - image: ghcr.io/lichess-org/lila-docker:ci + image: ghcr.io/lichess-org/lila-docker:main options: --restart=always steps: - name: Setup Python ${{ matrix.python-version }} diff --git a/integration/local b/integration/local index 2f3ac93..ef9ce49 100755 --- a/integration/local +++ b/integration/local @@ -1,6 +1,6 @@ #!/bin/bash -e -IMAGE=ghcr.io/lichess-org/lila-docker:ci +IMAGE=ghcr.io/lichess-org/lila-docker:main cleanup_containers() { docker rm --force lila > /dev/null 2>&1 || true From 61eb9752d41314afb8c38448337781c1f7125c55 Mon Sep 17 00:00:00 2001 From: kraktus Date: Sat, 19 Oct 2024 18:09:32 +0200 Subject: [PATCH 16/18] rename `integration/local` -> `integration/local.sh` --- integration/{local => local.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename integration/{local => local.sh} (100%) diff --git a/integration/local b/integration/local.sh similarity index 100% rename from integration/local rename to integration/local.sh From 0cf9e04e018af3b6f0a01bbd91b39ac7e2059a41 Mon Sep 17 00:00:00 2001 From: kraktus Date: Sat, 19 Oct 2024 18:25:44 +0200 Subject: [PATCH 17/18] refactor integration tests to be more robust against name collision --- integration/local.sh | 33 +++++++++++++++++++------------- integration/run-tests.sh | 2 +- integration/test_lila_account.py | 5 +++-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/integration/local.sh b/integration/local.sh index ef9ce49..422e0e3 100755 --- a/integration/local.sh +++ b/integration/local.sh @@ -1,19 +1,26 @@ #!/bin/bash -e -IMAGE=ghcr.io/lichess-org/lila-docker:main +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 lila > /dev/null 2>&1 || true - docker rm --force app > /dev/null 2>&1 || true - docker network rm lila-network > /dev/null 2>&1 || true -} + 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 + echo "Running integration tests" + cleanup_containers -docker network create lila-network -docker run --name lila --network lila-network -d $IMAGE -docker run --name app --network lila-network -v $(pwd):/app -w /app $IMAGE ./integration/run-tests.sh + 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" + cleanup_containers + echo "✅ Done" +} +integration_test \ No newline at end of file diff --git a/integration/run-tests.sh b/integration/run-tests.sh index 4ac2fb0..71126e3 100755 --- a/integration/run-tests.sh +++ b/integration/run-tests.sh @@ -4,7 +4,7 @@ python3 -m pip install -e . --no-cache-dir attempts=0 while [ $attempts -lt 30 ]; do - if curl -s http://lila:9663 >/dev/null; then + if curl -s http://bdit_lila:9663 >/dev/null; then break fi echo "⌛ Waiting for lila to start..." diff --git a/integration/test_lila_account.py b/integration/test_lila_account.py index 66c59fb..47a4062 100644 --- a/integration/test_lila_account.py +++ b/integration/test_lila_account.py @@ -1,12 +1,13 @@ 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="http://lila:9663") + session, base_url=BASE_URL) yield client @@ -34,7 +35,7 @@ def test_account_kid_mode(client): def test_account_upgrade_to_bot(): session = berserk.TokenSession('lip_zerogames') client = berserk.Client( - session, base_url="http://lila:9663") + session, base_url=BASE_URL) assert 'title' not in client.account.get() client.account.upgrade_to_bot() assert client.account.get()['title'] == "BOT" From cceb17261dfa093f5ceaa35dd239262faf2d8619 Mon Sep 17 00:00:00 2001 From: kraktus Date: Sat, 19 Oct 2024 18:38:29 +0200 Subject: [PATCH 18/18] Fix CI test and `make test` Otherwise pytest would try to run integration tests outside of the container --- .github/workflows/{lila.yml => integration_test.yml} | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{lila.yml => integration_test.yml} (98%) diff --git a/.github/workflows/lila.yml b/.github/workflows/integration_test.yml similarity index 98% rename from .github/workflows/lila.yml rename to .github/workflows/integration_test.yml index 535d390..87c5b1d 100644 --- a/.github/workflows/lila.yml +++ b/.github/workflows/integration_test.yml @@ -12,7 +12,7 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] container: ubuntu:22.04 services: - lila: + bdit_lila: image: ghcr.io/lichess-org/lila-docker:main options: --restart=always steps: diff --git a/Makefile b/Makefile index 25716b2..c93d454 100644 --- a/Makefile +++ b/Makefile @@ -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