Skip to content

Commit bf0e362

Browse files
authored
update tests (#29)
Update tests for #28. Add some diagnostic messages to troubleshoot CI.
1 parent e70f552 commit bf0e362

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

test/client/petstore_v3/petstore_test_userapi.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import OpenAPI.Clients: Client, Ctx, ApiException, DEFAULT_TIMEOUT_SECS, with_ti
1212
const TEST_USER = "jloac"
1313
const TEST_USER1 = "jloac1"
1414
const TEST_USER2 = "jloac2"
15+
const TEST_USER3 = "jl oac 3"
1516
const PRESET_TEST_USER = "user1" # this is the username that works for get user requests (as documented in the test docker container API)
1617

1718
function test_404(uri)
@@ -171,6 +172,21 @@ function test(uri)
171172
@test http_resp.status == 200
172173
@test logout_result === nothing
173174

175+
@info("UserApi - Test with spaces in username")
176+
user3 = User(; id=300, username=TEST_USER3, firstName="test3", lastName="user3", email="[email protected]", password="testpass3", phone="1000000003", userStatus=0)
177+
create_result, http_resp = create_user(api, user3)
178+
@test http_resp.status == 200
179+
@test create_result === nothing
180+
181+
user3.firstName = "test3 updated"
182+
api_return, http_resp = update_user(api, TEST_USER3, user3)
183+
@test http_resp.status == 200
184+
@test api_return === nothing
185+
186+
api_return, http_resp = delete_user(api, TEST_USER3)
187+
@test http_resp.status == 200
188+
@test api_return === nothing
189+
174190
nothing
175191
end
176192

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ include("client/allany/runtests.jl")
3636
end
3737
servers_running && OpenAPIClientTests.runtests()
3838
finally
39+
if run_tests_with_servers && !servers_running
40+
# we probably had an error starting the servers
41+
v2_out_str = isnothing(v2_out) ? "" : String(take!(v2_out))
42+
v3_out_str = isnothing(v3_out) ? "" : String(take!(v3_out))
43+
@warn("Servers not running", v2_ret=v2_ret, v2_out_str, v3_ret=v3_ret, v3_out_str)
44+
end
3945
if run_tests_with_servers
4046
stop_server(8080, v2_ret, v2_out)
4147
stop_server(8081, v3_ret, v3_out)
@@ -56,6 +62,11 @@ include("client/allany/runtests.jl")
5662
servers_running = false
5763
end
5864
finally
65+
if run_tests_with_servers && !servers_running
66+
# we probably had an error starting the servers
67+
out_str = isnothing(out) ? "" : String(take!(out))
68+
@warn("Servers not running", ret=ret, out_str)
69+
end
5970
run_tests_with_servers && stop_server(8081, ret, out)
6071
end
6172
end
@@ -75,6 +86,11 @@ include("client/allany/runtests.jl")
7586
servers_running = false
7687
end
7788
finally
89+
if run_tests_with_servers && !servers_running
90+
# we probably had an error starting the servers
91+
out_str = isnothing(out) ? "" : String(take!(out))
92+
@warn("Servers not running", ret=ret, out_str)
93+
end
7894
run_tests_with_servers && stop_server(8081, ret, out)
7995
end
8096
end

test/testutils.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ const startup_flag = `--startup-file=no`
99
const run_tests_with_servers = get(ENV, "RUNNER_OS", "") == "Linux"
1010

1111
function run_server(script, flags=``)
12-
srvrscript = joinpath(dirname(@__FILE__), script)
13-
srvrcmd = `$(joinpath(Sys.BINDIR, "julia")) $startup_flag $cov_flag $inline_flag $script $flags`
12+
use_pkgimages = VERSION >= v"1.9" ? `--pkgimages=no` : ``
13+
srvrcmd = `$(joinpath(Sys.BINDIR, "julia")) $use_pkgimages $startup_flag $cov_flag $inline_flag $script $flags`
14+
srvrcmd = addenv(srvrcmd,
15+
"JULIA_DEPOT_PATH"=>join(DEPOT_PATH, Sys.iswindows() ? ';' : ':'),
16+
"JULIA_LOAD_PATH"=>ENV["JULIA_LOAD_PATH"],
17+
)
1418
iob = IOBuffer()
1519
pipelined_cmd = pipeline(srvrcmd, stdout=iob, stderr=iob)
16-
ret = withenv("JULIA_DEPOT_PATH"=>join(DEPOT_PATH, Sys.iswindows() ? ';' : ':')) do
17-
@info("Launching ", script, srvrcmd, JULIA_DEPOT_PATH=ENV["JULIA_DEPOT_PATH"])
18-
run(pipelined_cmd, wait=false)
19-
end
20+
@info("Launching ", script, srvrcmd)
21+
ret = run(pipelined_cmd, wait=false)
2022

2123
return ret, iob
2224
end
@@ -55,7 +57,8 @@ function stop_server(port, proc, iob)
5557
wait(proc)
5658
@info("Stopped server", port)
5759
catch ex
58-
@warn("Error waiting for server", port, server_logs=String(take!(iob)), exception=(ex, catch_backtrace()))
60+
server_logs = isnothing(iob) ? "" : String(take!(iob))
61+
@warn("Error waiting for server", port, server_logs, exception=(ex, catch_backtrace()))
5962
return false
6063
end
6164

0 commit comments

Comments
 (0)