working on fixing dialing issue with http library
This commit is contained in:
@@ -9,7 +9,8 @@ import "core:thread"
|
||||
import http "../src"
|
||||
|
||||
SERVER_BODY :: "hello world"
|
||||
SERVER_RESPONSE := "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n" +
|
||||
SERVER_RESPONSE :=
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n" +
|
||||
"Content-Length: 11\r\n" +
|
||||
"Connection: close\r\n\r\n" +
|
||||
SERVER_BODY
|
||||
@@ -57,7 +58,9 @@ test_http_get_request :: proc(t: ^testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
args: Serve_Args = {listener = listener}
|
||||
args: Serve_Args = {
|
||||
listener = listener,
|
||||
}
|
||||
server_thread := thread.create_and_start_with_data(&args, serve_proc)
|
||||
defer thread.destroy(server_thread)
|
||||
|
||||
@@ -66,11 +69,81 @@ test_http_get_request :: proc(t: ^testing.T) {
|
||||
|
||||
log.infof("requesting %s", url)
|
||||
resp, req_err := http.http_get(url)
|
||||
if !testing.expect(t, req_err == nil, "http_get returned an error") {
|
||||
if !testing.expectf(t, req_err == nil, "http_get returned an error: %w", req_err) {
|
||||
return
|
||||
}
|
||||
defer delete(resp.body)
|
||||
|
||||
testing.expectf(t, resp.status == 200, "expected status 200, got %d", resp.status)
|
||||
testing.expectf(t, resp.body == SERVER_BODY, "expected %q, got %q", SERVER_BODY, resp.body)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_http_parse_url :: proc(t: ^testing.T) {
|
||||
testURL :: struct {
|
||||
url: string,
|
||||
expectedScheme: string,
|
||||
expectedOK: bool,
|
||||
expectedHost: string,
|
||||
expectedPort: int,
|
||||
expectedPath: string,
|
||||
}
|
||||
|
||||
testURLs := []testURL {
|
||||
{"http://localhost:8080", "http", true, "localhost", 8080, "/"},
|
||||
{"http://localhost", "http", true, "localhost", 80, "/"},
|
||||
{"https://localhost:443", "https", true, "localhost", 443, "/"},
|
||||
{"https://localhost", "https", true, "localhost", 443, "/"},
|
||||
{"http://test:6969", "http", true, "test", 6969, "/"},
|
||||
{
|
||||
"http://localhost:3000/api/v1/catalogs",
|
||||
"http",
|
||||
true,
|
||||
"localhost",
|
||||
3000,
|
||||
"/api/v1/catalogs",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
for tu in testURLs {
|
||||
scheme, host, port, path, ok := http.parse_http_url(tu.url)
|
||||
|
||||
testing.expectf(
|
||||
t,
|
||||
ok == tu.expectedOK,
|
||||
"expected ok from parsing to be %v but got %v",
|
||||
tu.expectedOK,
|
||||
ok,
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
host == tu.expectedHost,
|
||||
"expected host url to be '%s' but got '%s'",
|
||||
tu.expectedHost,
|
||||
host,
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
scheme == tu.expectedScheme,
|
||||
"expected scheme to be '%s' but got '%s'",
|
||||
tu.expectedScheme,
|
||||
scheme,
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
port == tu.expectedPort,
|
||||
"expected port to be %d but got %d",
|
||||
tu.expectedPort,
|
||||
port,
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
path == tu.expectedPath,
|
||||
"expected path to be '%s' but got '%s'",
|
||||
tu.expectedPath,
|
||||
path,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user