Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: initial support #4

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python package

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["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
pip install -r requirements-dev.txt

- name: Tests
run: pytest
24 changes: 11 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ description = "A Prometheus exporter for Typesense."
authors = [{name = "Solvik"}]
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.8"
requires-python = ">=3.9"

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

[dependencies]
certifi = "2024.12.14"
charset-normalizer = "3.4.1"
idna = "3.10"
prometheus-client = "0.16.0"
requests = "2.32.2"
typesense = "0.21.0"
urllib3 = "2.3.0"
[tool.pytest.ini_options]
addopts = "-v --cov=typesense_exporter --cov-report=term-missing --cov-report=xml --cov-report=html"
testpaths = ["tests"]
asyncio_mode = "auto"

[dev-dependencies]
pytest = "^7.0"
mypy = "^1.14"
types-requests = "^2.32"
[tool.coverage.run]
branch = true
source = ["typesense_exporter"]

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

[build-system]
requires = ["setuptools", "wheel"]
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
8 changes: 7 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
-e .
certifi==2024.12.14
charset-normalizer==3.4.1
idna==3.10
prometheus-client==0.16.0
requests==2.32.2
typesense==0.21.0
urllib3==2.3.0
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
Loading