Skip to content
Snippets Groups Projects
Commit 8a8e94df authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

fix: test_http_server on mac

Picodata treats absent hostname (`:8080`) as `localhost` by default,
which resolves to IPv6 on Mac. The test explicitly specified
inconsistent addresses, and that caused "connection refused" error.
parent 1bd766f7
No related branches found
No related tags found
1 merge request!584fix: test_http_server on mac
Pipeline #20027 passed
from conftest import Cluster
from conftest import Cluster, Instance
from urllib.request import urlopen
import pytest
def test_server_works(cluster: Cluster):
@pytest.fixture
def instance(cluster: Cluster):
instance = cluster.add_instance(wait_online=False)
script = f"{cluster.data_dir}/add_routes.lua"
with open(script, "w") as f:
f.write(
"""
function handler(req)
return {
status = 200,
headers = { ['content-type'] = 'text/html; charset=utf8' },
body = 'world'
}
end
pico.httpd:route({path = '/hello', method = 'GET'}, handler)
"""
)
instance.env["PICODATA_SCRIPT"] = script
instance.env["PICODATA_HTTP_LISTEN"] = ":8080"
instance.env["PICODATA_HTTP_LISTEN"] = f"{cluster.base_host}:{cluster.base_port+80}"
instance.start()
instance.wait_online()
with urlopen("http://127.0.0.1:8080/hello") as response:
return instance
def test_http_routes(instance: Instance):
instance.eval(
"""
pico.httpd:route({path = '/hello', method = 'GET'}, function(req)
return {
status = 200,
body = 'world'
}
end)
"""
)
http_listen = instance.env["PICODATA_HTTP_LISTEN"]
with urlopen(f"http://{http_listen}/hello") as response:
assert response.read() == b"world"
def test_webui(cluster: Cluster):
instance = cluster.add_instance(wait_online=False)
instance.env["PICODATA_HTTP_LISTEN"] = ":8081"
instance.start()
instance.wait_online()
with urlopen("http://127.0.0.1:8081") as response:
def test_webui(instance: Instance):
http_listen = instance.env["PICODATA_HTTP_LISTEN"]
with urlopen(f"http://{http_listen}/") as response:
assert response.headers.get("content-type") == "text/html"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment