Files
jianda-proxy/tests/test_proxy.py
2026-05-28 17:50:32 +08:00

47 lines
1.4 KiB
Python

import pytest
from jianda_proxy.proxy import create_server
class TestCreateServer:
def test_creates_server_with_config(self):
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19999",
}
server = create_server(config)
assert server is not None
server.server_close()
def test_binds_to_correct_port(self):
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19998",
}
server = create_server(config)
assert server.server_address[1] == 19998
server.server_close()
class TestProxyHandler:
def test_forward_proxy_mode(self):
from jianda_proxy.proxy import ProxyHandler
config = {
"remote_domain": "git.example.com",
"upstream_host": "1.2.3.4",
"upstream_port": "9000",
"listen_host": "127.0.0.1",
"listen_port": "19997",
}
server = create_server(config)
# Verify the handler has the correct config set as class attributes
assert hasattr(ProxyHandler, "REMOTE_DOMAIN")
assert ProxyHandler.REMOTE_DOMAIN == "git.example.com"
server.server_close()