Skip to content

Commit f01084b

Browse files
committed
test: add tests for node class initialization
Implement comprehensive test suite for Node class functionality: - Test basic initialization and attribute setting - Validate URL parsing with Node.from_url method - Add error handling tests for invalid URL inputs - Ensure correct URL generation with url() method
1 parent 6ac5c3e commit f01084b

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

tests/__init__.py

Whitespace-only changes.

tests/node_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
from src.typesense.configuration import Node
4+
from src.typesense.exceptions import ConfigError
5+
6+
7+
def test_node_initialization():
8+
node = Node(host="localhost", port=8108, path="/path", protocol="http")
9+
assert node.host == "localhost"
10+
assert node.port == 8108
11+
assert node.path == "/path"
12+
assert node.protocol == "http"
13+
assert node.healthy is True
14+
15+
16+
def test_node_from_url():
17+
node = Node.from_url("http://localhost:8108/path")
18+
assert node.host == "localhost"
19+
assert node.port == 8108
20+
assert node.path == "/path"
21+
assert node.protocol == "http"
22+
23+
24+
def test_node_from_url_missing_hostname():
25+
with pytest.raises(ConfigError, match="Node URL does not contain the host name."):
26+
Node.from_url("http://:8108/path")
27+
28+
29+
def test_node_from_url_missing_port():
30+
with pytest.raises(ConfigError, match="Node URL does not contain the port."):
31+
Node.from_url("http://localhost:/path")
32+
33+
34+
def test_node_from_url_missing_scheme():
35+
with pytest.raises(ConfigError, match="Node URL does not contain the protocol."):
36+
Node.from_url("//localhost:8108/path")
37+
38+
39+
def test_node_url():
40+
node = Node(host="localhost", port=8108, path="/path", protocol="http")
41+
assert node.url() == "http://localhost:8108/path"

0 commit comments

Comments
 (0)