From 3b40ff280c30f08435f3d50529fa33d1a33d048f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 30 Oct 2020 10:11:15 +0100 Subject: [PATCH] ci: add tests github action --- .github/workflows/tests.yaml | 69 ++++++++++++++++++++++++++++++++++++ tests/test_broadcast.py | 45 ++++++++++++----------- 2 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..f13c4a0 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,69 @@ + +name: Tests on platforms + +on: + pull_request: + branches: + - master + +jobs: + redis: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Start containers + run: docker-compose -f "docker-compose.yaml" up -d --build redis + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install pytest + - name: Run tests + run: pytest -m redis tests/ + - name: Stop containers + if: always() + run: docker-compose -f "docker-compose.yaml" down + kafka: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Start containers + run: docker-compose -f "docker-compose.yaml" up -d --build kafka + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install pytest + - name: Run tests + run: pytest -m kafka tests/ + - name: Stop containers + if: always() + run: docker-compose -f "docker-compose.yaml" down + postgres: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Start containers + run: docker-compose -f "docker-compose.yaml" up -d --build postgres + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install pytest + - name: Run tests + run: pytest -m postgres tests/ + - name: Stop containers + if: always() + run: docker-compose -f "docker-compose.yaml" down \ No newline at end of file diff --git a/tests/test_broadcast.py b/tests/test_broadcast.py index 7e0c8c0..d8f21e0 100644 --- a/tests/test_broadcast.py +++ b/tests/test_broadcast.py @@ -5,39 +5,44 @@ @pytest.mark.asyncio async def test_memory(): - async with Broadcast('memory://') as broadcast: - async with broadcast.subscribe('chatroom') as subscriber: - await broadcast.publish('chatroom', 'hello') + async with Broadcast("memory://") as broadcast: + async with broadcast.subscribe("chatroom") as subscriber: + await broadcast.publish("chatroom", "hello") event = await subscriber.get() - assert event.channel == 'chatroom' - assert event.message == 'hello' + assert event.channel == "chatroom" + assert event.message == "hello" @pytest.mark.asyncio +@pytest.mark.redis async def test_redis(): - async with Broadcast('redis://localhost:6379') as broadcast: - async with broadcast.subscribe('chatroom') as subscriber: - await broadcast.publish('chatroom', 'hello') + async with Broadcast("redis://localhost:6379") as broadcast: + async with broadcast.subscribe("chatroom") as subscriber: + await broadcast.publish("chatroom", "hello") event = await subscriber.get() - assert event.channel == 'chatroom' - assert event.message == 'hello' + assert event.channel == "chatroom" + assert event.message == "hello" @pytest.mark.asyncio +@pytest.mark.postgres async def test_postgres(): - async with Broadcast('postgres://postgres:postgres@localhost:5432/broadcaster') as broadcast: - async with broadcast.subscribe('chatroom') as subscriber: - await broadcast.publish('chatroom', 'hello') + async with Broadcast( + "postgres://postgres:postgres@localhost:5432/broadcaster" + ) as broadcast: + async with broadcast.subscribe("chatroom") as subscriber: + await broadcast.publish("chatroom", "hello") event = await subscriber.get() - assert event.channel == 'chatroom' - assert event.message == 'hello' + assert event.channel == "chatroom" + assert event.message == "hello" @pytest.mark.asyncio +@pytest.mark.kafka async def test_kafka(): - async with Broadcast('kafka://localhost:9092') as broadcast: - async with broadcast.subscribe('chatroom') as subscriber: - await broadcast.publish('chatroom', 'hello') + async with Broadcast("kafka://localhost:9092") as broadcast: + async with broadcast.subscribe("chatroom") as subscriber: + await broadcast.publish("chatroom", "hello") event = await subscriber.get() - assert event.channel == 'chatroom' - assert event.message == 'hello' + assert event.channel == "chatroom" + assert event.message == "hello"