Skip to content

Commit

Permalink
Tests updates
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Oct 4, 2020
1 parent 407faf9 commit 6ab8ed2
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 39 deletions.
13 changes: 9 additions & 4 deletions src/AppServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function startup(port::Int, host::String = Genie.config.server_host;
verbose::Bool = false, ratelimit::Union{Rational{Int},Nothing} = nothing,
server::Union{Sockets.TCPServer,Nothing} = nothing, wsserver::Union{Sockets.TCPServer,Nothing} = nothing,
ssl_config::Union{MbedTLS.SSLConfig,Nothing} = Genie.config.ssl_config,
open_browser::Bool = Genie.Configuration.isdev(),
open_browser::Bool = false,
http_kwargs...) :: ServersCollection

update_config(port, host, ws_port)
Expand Down Expand Up @@ -89,12 +89,17 @@ function startup(port::Int, host::String = Genie.config.server_host;
command()
end

@info status

if status.state == :runnable
SERVERS.webserver = status

print_server_status("Web Server running at $server_url")
open_browser && openbrowser(server_url)

try
open_browser && openbrowser(server_url)
catch ex
@error "Failed to open browser"
@error ex
end
end

SERVERS
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ env() :: String = Genie.config.app_env
Constructs the temp dir where Genie's view files are built.
"""
buildpath() :: String = Base.Filesystem.mktempdir(prefix = "jl_genie_build_", cleanup = false)
buildpath() :: String = Base.Filesystem.mktempdir(prefix = "jl_genie_build_")


"""
Expand Down
13 changes: 9 additions & 4 deletions src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const JULIA_PATH = joinpath(Sys.BINDIR, "julia")


function validname(name::String)
filter(! isempty, [x.match for x in collect(eachmatch(r"[0-9a-zA-Z_\\/:]*", name))]) |> join
filter(! isempty, [x.match for x in collect(eachmatch(r"[0-9a-zA-Z_]*", name))]) |> join
end


Expand Down Expand Up @@ -214,9 +214,11 @@ end
Writes the files necessary to create a full stack Genie app.
"""
function fullstack_app(app_path::String = ".") :: Nothing
function fullstack_app(app_name::String = ".", app_path::String = ".") :: Nothing
cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH), app_path)

scaffold(app_name, app_path)

nothing
end

Expand Down Expand Up @@ -251,7 +253,10 @@ function scaffold(app_name::String, app_path::String = "") :: Nothing

for f in [Genie.config.path_src, Genie.GENIE_FILE_NAME, Genie.ROUTES_FILE_NAME,
".gitattributes", ".gitignore"]
cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH, f), joinpath(app_path, f))
try
cp(joinpath(@__DIR__, "..", Genie.NEW_APP_PATH, f), joinpath(app_path, f))
catch ex
end
end

write_app_custom_files(app_name, app_path)
Expand Down Expand Up @@ -439,7 +444,7 @@ function newapp(app_name::String; autostart::Bool = true, fullstack::Bool = fals
app_name = validname(app_name)
app_path = abspath(app_name)

fullstack ? fullstack_app(app_path) : microstack_app(app_name, app_path)
fullstack ? fullstack_app(app_name, app_path) : microstack_app(app_name, app_path)

dbsupport ? (fullstack || db_support(app_path)) : remove_searchlight_initializer(app_path)

Expand Down
1 change: 1 addition & 0 deletions src/Genie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const newapp = Generator.newapp
const newapp_webservice = Generator.newapp_webservice
const newapp_mvc = Generator.newapp_mvc
const newapp_fullstack = Generator.newapp_fullstack
const new = Generator.new


"""
Expand Down
2 changes: 1 addition & 1 deletion test/cors/cors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ route("/random", method=POST) do
(:random => rand(dim,num)) |> json
end

up()
up(; open_browser = false)
2 changes: 1 addition & 1 deletion test/fileuploads/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ route("/", method = POST) do
@params(:greeting)
end

Genie.AppServer.startup(async = false)
Genie.AppServer.startup(; open_browser = false, async = false)
2 changes: 1 addition & 1 deletion test/getargsparse/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ convert(::Type{Date}, s::SubString{String}) = Date(s)
route("/getparams/:s::String/:f::Float64/:i::Int/:d::Date") do
@show "s = $(@params(:s)) / f = $(@params(:f)) / i = $(@params(:i)) / $(@params(:d))"
end
Genie.AppServer.startup()
Genie.AppServer.startup(; open_browser = false)

HTTP.get("http://localhost:8000/getparams/foo/23.43/18/2019-02-15")

Expand Down
2 changes: 1 addition & 1 deletion test/headers/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ route("/headers", method = OPTIONS) do
setstatus(200)
end

Genie.AppServer.startup(verbose = true)
Genie.AppServer.startup(; open_browser = false, verbose = true)

response = HTTP.request("GET", "http://localhost:8000/headers") # unhandled, should get default response
@show response
Expand Down
2 changes: 1 addition & 1 deletion test/hello/perftest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import Genie.Router: route
route("/hello") do
"Welcome to Genie!"
end
Genie.AppServer.startup(async = false)
Genie.AppServer.startup(; open_browser = false, async = false)
2 changes: 1 addition & 1 deletion test/hello/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Genie.Router: route
route("/hello") do
"Welcome to Genie!"
end
Genie.AppServer.startup()
Genie.AppServer.startup(; open_browser = false)

HTTP.get("http://localhost:8000/hello")

Expand Down
2 changes: 1 addition & 1 deletion test/htmlrendering/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ route("/") do
html(markup)
end

Genie.AppServer.startup(async = false)
Genie.AppServer.startup(; open_browser = false, async = false)
2 changes: 1 addition & 1 deletion test/inlinecache/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ route("/test") do
"All good"
end

Genie.AppServer.startup(async = true)
Genie.AppServer.startup(; open_browser = false, async = true)
2 changes: 1 addition & 1 deletion test/json-error/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ route("/json-error", method = POST) do
error("500, sorry")
end

Genie.AppServer.startup()
Genie.AppServer.startup(; open_browser = false)

@test_throws HTTP.ExceptionRequest.StatusError HTTP.request("POST", "http://localhost:8000/json-error", [("Content-Type", "application/json; charset=utf-8")], """{"greeting":"hello"}""")

Expand Down
2 changes: 1 addition & 1 deletion test/jsonpayload/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ route("/jsontest", method = POST) do
json_request["test"]
end

Genie.AppServer.startup()
Genie.AppServer.startup(; open_browser = false)

HTTP.request("POST", "http://localhost:8000/jsonpayload", [("Content-Type", "application/json; charset=utf-8")], """{"greeting":"hello"}""")
HTTP.request("POST", "http://localhost:8000/jsonpayload", [("Content-Type", "application/json")], """{"greeting":"hello"}""")
Expand Down
2 changes: 1 addition & 1 deletion test/optionsrequest/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Genie.Router
route("/options", method = OPTIONS) do
push!(@params(:RESPONSE).headers, "X-Foo-Bar"=>"Baz")
end
Genie.AppServer.startup(verbose = true)
Genie.AppServer.startup(; open_browser = false, verbose = true)

response = HTTP.request("OPTIONS", "http://localhost:8000") # unhandled, should get default response
@show response
Expand Down
2 changes: 1 addition & 1 deletion test/postform/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ route("/", method = POST) do
@params(:greeting)
end

Genie.AppServer.startup(async = false)
Genie.AppServer.startup(; open_browser = false, async = false)
2 changes: 1 addition & 1 deletion test/responses/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ route("/broken") do
omg!()
end

Genie.AppServer.startup(verbose = true)
Genie.AppServer.startup(; open_browser = false, verbose = true)

response = HTTP.request("GET", "http://localhost:8000/responses")
@show response
Expand Down
6 changes: 3 additions & 3 deletions test/tests_AppServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Genie
using Genie.AppServer

servers = Genie.AppServer.startup()
servers = Genie.AppServer.startup(; open_browser = false)
@test servers.webserver.state == :runnable
@test Genie.AppServer.SERVERS.webserver.state == :runnable

Expand All @@ -13,7 +13,7 @@
@test servers.webserver.state == :done
@test Genie.AppServer.SERVERS.webserver.state == :done

servers = Genie.AppServer.startup()
servers = Genie.AppServer.startup(; open_browser = false)
Genie.AppServer.down(; webserver = false)
sleep(2)
@test servers.webserver.state == :runnable
Expand All @@ -32,7 +32,7 @@
port = Genie.config.server_port
ws_port = Genie.config.websockets_port

Genie.AppServer.up(port+1_000; ws_port = ws_port+1_000)
Genie.AppServer.up(port+1_000; ws_port = ws_port+1_000, open_browser = false)

@test Genie.config.server_port == port+1_000
@test Genie.config.websockets_port == ws_port+1_000
Expand Down
2 changes: 1 addition & 1 deletion test/tests_Sessions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"$(Sessions.get(sess, :visit_count))"
end

Genie.up()
Genie.up(; open_browser = false)

# TODO: extend to use the cookie and increment the count
response = HTTP.get("http://$(Genie.config.server_host):$(Genie.config.server_port)/home")
Expand Down
4 changes: 2 additions & 2 deletions test/tests_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@test Genie.config.websockets_port == 8000
@test Genie.config.run_as_server == false

up(9000, "0.0.0.0")
up(9000, "0.0.0.0"; open_browser = false)

@test Genie.config.server_port == 9000
@test Genie.config.server_host == "0.0.0.0"
Expand All @@ -16,7 +16,7 @@

down()

up(9000, "0.0.0.0", ws_port = 9999)
up(9000, "0.0.0.0", ws_port = 9999; open_browser = false)

@test Genie.config.server_port == 9000
@test Genie.config.server_host == "0.0.0.0"
Expand Down
20 changes: 10 additions & 10 deletions test/tests_content_negotiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "text/html"])
Expand Down Expand Up @@ -34,7 +34,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Accept" => "text/html"])
Expand Down Expand Up @@ -63,7 +63,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "application/json"])
Expand Down Expand Up @@ -92,7 +92,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Accept" => "application/json"])
Expand Down Expand Up @@ -121,7 +121,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "text/plain"])
Expand Down Expand Up @@ -151,7 +151,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "text/csv"])
Expand Down Expand Up @@ -180,7 +180,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Accept" => "text/csv"])
Expand Down Expand Up @@ -209,7 +209,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "text/csv"])
Expand Down Expand Up @@ -252,7 +252,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Content-Type" => "application/json"])
Expand Down Expand Up @@ -295,7 +295,7 @@
using Genie
using HTTP

Genie.up()
Genie.up(; open_browser = false)

response = try
HTTP.request("GET", "http://127.0.0.1:8000/notexisting", ["Accept" => "text/html, text/plain, application/json, text/csv"])
Expand Down
1 change: 1 addition & 0 deletions test/tests_fullstack_app.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
cd(workdir)

Genie.newapp("fullstack_test", fullstack = true, testmode = true)

Genie.Generator.newcontroller("Foo", pluralize = false)
@test isfile(joinpath("app", "resources", "foo", "FooController.jl")) == true

Expand Down
Loading

2 comments on commit 6ab8ed2

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/22399

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.0 -m "<description of version>" 6ab8ed26debdd215f2b230e3fa44e420d0c20d38
git push origin v1.5.0

Please sign in to comment.