Skip to content

Commit

Permalink
test: initial support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lujeni committed Dec 30, 2024
1 parent 48de097 commit 2441456
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Python package

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r dev-requirements.txt
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ pytest = "^7.0"
mypy = "^1.14"
types-requests = "^2.32"

[tool.pytest.ini_options]
addopts = "-v --cov=typesense_exporter --cov-report=term-missing --cov-report=xml --cov-report=html"
testpaths = ["tests"]
asyncio_mode = "auto"

[tool.coverage.run]
branch = true
source = ["typesense_exporter"]

[tool.coverage.html]
directory = "coverage_html"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mypy>=1.14
pytest-asyncio>=0.23.5
pytest-cov>=4.1
pytest>=7.0
types-requests>=2.32
Empty file added tests/__init__.py
Empty file.
Empty file added tests/conftest.py
Empty file.
37 changes: 37 additions & 0 deletions tests/test_typesense_exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest
from typesense_exporter import parse_nodes_from_str


@pytest.mark.parametrize("test_input,expected,protocol,description", [
(
"localhost:8108",
[{"host": "localhost", "port": "8108", "protocol": "https"}],
"https",
"single node with port"
),
(
"host1:8108,host2:8108",
[
{"host": "host1", "port": "8108", "protocol": "https"},
{"host": "host2", "port": "8108", "protocol": "https"}
],
"https",
"multiple nodes"
),
(
"localhost",
[{"host": "localhost", "port": "8108", "protocol": "https"}],
"https",
"default port"
),
(
"localhost:8108",
[{"host": "localhost", "port": "8108", "protocol": "http"}],
"http",
"custom protocol"
),
])
def test_parse_nodes_from_str(test_input, expected, protocol, description):
nodes = parse_nodes_from_str(test_input, default_protocol=protocol)
assert len(nodes) == len(expected)
assert nodes == expected

0 comments on commit 2441456

Please sign in to comment.