Skip to content

Commit ba66d96

Browse files
committed
fix: type instability with _api_registries
1 parent 93aa064 commit ba66d96

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
77
### Fixed
88

99
* Fixed the submission of application-type jobs. (#31, #32, #33)
10+
* `JuliaHub.applications()` no longer throws a type error when the user has no registered and user applications. (#33)
1011

1112
## Version v0.1.4 - 2023-08-21
1213

src/applications.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ struct _RegistryInfo
2121
end
2222
end
2323

24-
function _api_registries(auth::Authentication)
24+
function _api_registries(auth::Authentication)::Vector{_RegistryInfo}
2525
r = _restcall(auth, :GET, "app", "packages", "registries")
2626
json, _ = _parse_response_json(r, Dict)
2727
_json_check_success(json; var="app/packages/registries")
2828
registries = _json_get(json, "registries", Vector; var="app/packages/registries")
29+
# Note: this broadcast can return Any[] if `registries` is empty, hence
30+
# the need for a return type.
2931
return _RegistryInfo.(registries; var="app/packages/registries")
3032
end
3133

test/applications.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ end
2323
end
2424
end
2525

26+
@testset "Empty user/registered apps" begin
27+
MOCK_JULIAHUB_STATE[:app_packages_registries] = []
28+
MOCK_JULIAHUB_STATE[:app_applications_info] = []
29+
MOCK_JULIAHUB_STATE[:app_applications_myapps] = []
30+
Mocking.apply(mocking_patch) do
31+
@test length(JuliaHub.applications()) == 4
32+
@test length(JuliaHub.applications(:default)) == 4
33+
@test length(JuliaHub.applications(:package)) == 0
34+
@test length(JuliaHub.applications(:user)) == 0
35+
end
36+
empty!(MOCK_JULIAHUB_STATE)
37+
end
38+
2639
TEST_SUBMIT_APPS = [
2740
(:default, "Pluto", JuliaHub.DefaultApp),
2841
(:package, "RegisteredPackageApp", JuliaHub.PackageApp),

test/mocking.jl

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,16 @@ function _restcall_mocked(method, url, headers, payload; query)
203203
],
204204
) |> jsonresponse(200)
205205
elseif (method == :GET) && endswith(url, "app/packages/registries")
206-
Dict(
207-
"success" => true, "message" => "",
208-
"registries" => [
206+
packages_registries = get(MOCK_JULIAHUB_STATE, :app_packages_registries) do
207+
[
209208
#! format: off
210209
Dict("name" => "General", "uuid" => "23338594-aafe-5451-b93e-139f81909106", "id" => 1),
211210
Dict("name" => "JuliaComputingRegistry", "uuid" => "bbcd6645-47a4-41f8-a415-d8fc8421bd34", "id" => 266),
212211
#! format: on
213-
],
212+
]
213+
end
214+
Dict(
215+
"success" => true, "message" => "", "registries" => packages_registries
214216
) |> jsonresponse(200)
215217
elseif (method == :GET) && endswith(url, "app/applications/default")
216218
r = if apiv >= v"0.0.1"
@@ -251,27 +253,33 @@ function _restcall_mocked(method, url, headers, payload; query)
251253
end
252254
r |> jsonresponse(200)
253255
elseif (method == :GET) && endswith(url, "app/applications/info")
254-
Any[
255-
Dict(
256-
"name" => "RegisteredPackageApp",
257-
"uuid" => "db8b4d46-bfad-4aa5-a5f8-40df1e9542e5",
258-
"registrymap" => Any[Dict("status" => true, "id" => "1")],
259-
),
260-
Dict(
261-
"name" => "CustomDashboardApp",
262-
"uuid" => "539b0f2a-a771-427e-a3ea-5fa1ee615c0c",
263-
"registrymap" => Any[Dict("status" => true, "id" => "266")],
264-
),
265-
] |> jsonresponse(200)
256+
applications_info = get(MOCK_JULIAHUB_STATE, :app_applications_info) do
257+
Any[
258+
Dict(
259+
"name" => "RegisteredPackageApp",
260+
"uuid" => "db8b4d46-bfad-4aa5-a5f8-40df1e9542e5",
261+
"registrymap" => Any[Dict("status" => true, "id" => "1")],
262+
),
263+
Dict(
264+
"name" => "CustomDashboardApp",
265+
"uuid" => "539b0f2a-a771-427e-a3ea-5fa1ee615c0c",
266+
"registrymap" => Any[Dict("status" => true, "id" => "266")],
267+
),
268+
]
269+
end
270+
applications_info |> jsonresponse(200)
266271
elseif (method == :GET) && endswith(url, "app/applications/myapps")
267-
#! format: off
268-
Any[
269-
Dict(
270-
"name" => "ExampleApp.jl",
271-
"repourl" => "https://github.com/JuliaHubExampleOrg/ExampleApp.jl",
272-
),
273-
] |> jsonresponse(200)
274-
#! format: on
272+
applications_myapps = get(MOCK_JULIAHUB_STATE, :app_applications_myapps) do
273+
#! format: off
274+
Any[
275+
Dict(
276+
"name" => "ExampleApp.jl",
277+
"repourl" => "https://github.com/JuliaHubExampleOrg/ExampleApp.jl",
278+
),
279+
]
280+
#! format: on
281+
end
282+
applications_myapps |> jsonresponse(200)
275283
elseif (method == :POST) && endswith(url, "juliaruncloud/submit_job")
276284
jobname = "jr-xf4tslavut"
277285
Dict("message" => "", "success" => true, "jobname" => jobname) |> jsonresponse(200)

0 commit comments

Comments
 (0)