-
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.
Add GH workflow Signed-off-by: Ygal Blum <[email protected]>
- Loading branch information
Showing
4 changed files
with
110 additions
and
12 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,40 @@ | ||
name: E2E Test | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_call: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-24.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Build Image | ||
id: build-image | ||
uses: redhat-actions/buildah-build@v2 | ||
with: | ||
image: slack_server_mock | ||
tags: latest | ||
containerfiles: | | ||
./Containerfile | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r test/requirements.txt | ||
- name: Run tests | ||
run: | | ||
pytest 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
slack_bolt | ||
pytest | ||
requests |
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,53 @@ | ||
from pathlib import Path | ||
import time | ||
import subprocess | ||
|
||
import pytest | ||
import requests | ||
from slackbot import KnowledgeBaseSlackBot | ||
|
||
|
||
# Fixture to manage Podman container lifecycle | ||
@pytest.fixture(scope="module") | ||
def podman_container(): | ||
container_name = "slack_server_mock" | ||
image = "quay.io/yblum/slack_server_mock:0.0.1" | ||
ports = [3001, 8080, 8888] | ||
project_root_path = Path(__file__).parents[1] | ||
volumes = [f"{project_root_path}/settings.yaml:/app/settings.yaml:z"] | ||
|
||
podman_run_command = ["podman", "run", "--name", container_name, "-d", "--rm"] | ||
for port in ports: | ||
podman_run_command.extend(["--publish", f"{port}:{port}"]) | ||
for volume in volumes: | ||
podman_run_command.extend(["--volume", volume]) | ||
podman_run_command.append(image) | ||
# Start the container | ||
print("Starting Podman container...") | ||
subprocess.run(podman_run_command, check=True) | ||
|
||
# Wait a bit for the container to be fully up and running | ||
time.sleep(5) | ||
|
||
# Provide the container name to the test | ||
yield container_name | ||
|
||
# Stop and remove the container after tests | ||
print("Stopping Podman container...") | ||
subprocess.run(["podman", "kill", container_name], check=True) | ||
|
||
|
||
@pytest.fixture | ||
def bot(): | ||
bot = KnowledgeBaseSlackBot() | ||
bot.run() | ||
while not bot.is_connected(): | ||
time.sleep(1) | ||
yield bot | ||
bot.stop() | ||
|
||
|
||
def test_echo(bot, podman_container): | ||
msg = "foo" | ||
res = requests.post(url="http://localhost:8080/message", json={"message": msg}) | ||
assert res.json().get('answer') == msg |