Skip to content

Commit

Permalink
renamed context to payload
Browse files Browse the repository at this point in the history
  • Loading branch information
ndortega committed Jan 3, 2025
1 parent c046fbf commit 0e0a765
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Nullable{T} = Union{T, Nothing}

# Represents the application context
struct Context{T}
context::T
payload::T
end

# Represents a running task
Expand Down
31 changes: 9 additions & 22 deletions test/appcontexttests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ end
return "Hello World"
end

@get "/ctx" function(req)
return json(context())
end

@get "/injected" function(req, ctx::Context{Person})
return json(ctx.context)
return json(ctx.payload)
end

serve(port=PORT, host=HOST, async=true, show_errors=false, show_banner=false, access_log=nothing)
serve(port=PORT, host=HOST, async=true, show_errors=false, show_banner=false, access_log=nothing)

terminate()

@testset "null context tests" begin
@test context() isa Missing
@test context() === missing
@testset "null context tests" begin
try
response = HTTP.get("$localhost/injected")
catch e
@test e isa HTTP.Exception
@test e.status == 500
end
end

terminate()
Expand All @@ -42,23 +40,12 @@ serve(port=PORT, host=HOST, async=true, show_errors=false, show_banner=false, ac
@test text(response) == "Hello World"
end

@testset "accessing context from a function handler" begin
response = HTTP.get("$localhost/ctx")
@test response.status == 200
@test json(response, Person) == person
end

@testset "accessing injected context from a function handler" begin
response = HTTP.get("$localhost/injected")
@test response.status == 200
@test json(response, Person) == person
end

@testset "Non-null context tests" begin
@test context() isa Person
@test context() === person
end

terminate()

end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include("paralleltests.jl")
include("taskmanagement.jl")
include("cronmanagement.jl")
include("middlewaretests.jl")
include("./appcontexttests.jl")
include("appcontexttests.jl")
include("originaltests.jl")

#### Scenario Tests ####
Expand Down

0 comments on commit 0e0a765

Please sign in to comment.