Skip to content

Commit 7588df1

Browse files
committed
test: initial support
1 parent 822bf1c commit 7588df1

File tree

7 files changed

+90
-14
lines changed

7 files changed

+90
-14
lines changed

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.9", "3.10", "3.11", "3.12"]
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- name: Display Python version
21+
run: python -c "import sys; print(sys.version)"
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements.txt
27+
pip install -r requirements-dev.txt
28+
29+
- name: Tests
30+
run: pytest

pyproject.toml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@ description = "A Prometheus exporter for Typesense."
55
authors = [{name = "Solvik"}]
66
readme = "README.md"
77
license = {file = "LICENSE"}
8-
requires-python = ">=3.8"
8+
requires-python = ">=3.9"
99

1010
[project.urls]
1111
homepage = "https://github.com/numberly/typesense_exporter"
1212
repository = "https://github.com/numberly/typesense_exporter"
1313

14-
[dependencies]
15-
certifi = "2024.12.14"
16-
charset-normalizer = "3.4.1"
17-
idna = "3.10"
18-
prometheus-client = "0.16.0"
19-
requests = "2.32.2"
20-
typesense = "0.21.0"
21-
urllib3 = "2.3.0"
14+
[tool.pytest.ini_options]
15+
addopts = "-v --cov=typesense_exporter --cov-report=term-missing --cov-report=xml --cov-report=html"
16+
testpaths = ["tests"]
17+
asyncio_mode = "auto"
2218

23-
[dev-dependencies]
24-
pytest = "^7.0"
25-
mypy = "^1.14"
26-
types-requests = "^2.32"
19+
[tool.coverage.run]
20+
branch = true
21+
source = ["typesense_exporter"]
22+
23+
[tool.coverage.html]
24+
directory = "coverage_html"
2725

2826
[build-system]
2927
requires = ["setuptools", "wheel"]

requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mypy>=1.14
2+
pytest-asyncio>=0.23.5
3+
pytest-cov>=4.1
4+
pytest>=7.0
5+
types-requests>=2.32

requirements.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
-e .
1+
certifi==2024.12.14
2+
charset-normalizer==3.4.1
3+
idna==3.10
4+
prometheus-client==0.16.0
5+
requests==2.32.2
6+
typesense==0.21.0
7+
urllib3==2.3.0

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Whitespace-only changes.

tests/test_typesense_exporter.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from typesense_exporter import parse_nodes_from_str
3+
4+
5+
@pytest.mark.parametrize("test_input,expected,protocol,description", [
6+
(
7+
"localhost:8108",
8+
[{"host": "localhost", "port": "8108", "protocol": "https"}],
9+
"https",
10+
"single node with port"
11+
),
12+
(
13+
"host1:8108,host2:8108",
14+
[
15+
{"host": "host1", "port": "8108", "protocol": "https"},
16+
{"host": "host2", "port": "8108", "protocol": "https"}
17+
],
18+
"https",
19+
"multiple nodes"
20+
),
21+
(
22+
"localhost",
23+
[{"host": "localhost", "port": "8108", "protocol": "https"}],
24+
"https",
25+
"default port"
26+
),
27+
(
28+
"localhost:8108",
29+
[{"host": "localhost", "port": "8108", "protocol": "http"}],
30+
"http",
31+
"custom protocol"
32+
),
33+
])
34+
def test_parse_nodes_from_str(test_input, expected, protocol, description):
35+
nodes = parse_nodes_from_str(test_input, default_protocol=protocol)
36+
assert len(nodes) == len(expected)
37+
assert nodes == expected

0 commit comments

Comments
 (0)