From 6ab8ed26debdd215f2b230e3fa44e420d0c20d38 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Sun, 4 Oct 2020 19:06:53 +0200 Subject: [PATCH] Tests updates --- src/AppServer.jl | 13 +++++++++---- src/Configuration.jl | 2 +- src/Generator.jl | 13 +++++++++---- src/Genie.jl | 1 + test/cors/cors.jl | 2 +- test/fileuploads/test.jl | 2 +- test/getargsparse/test.jl | 2 +- test/headers/test.jl | 2 +- test/hello/perftest.jl | 2 +- test/hello/test.jl | 2 +- test/htmlrendering/test.jl | 2 +- test/inlinecache/test.jl | 2 +- test/json-error/test.jl | 2 +- test/jsonpayload/test.jl | 2 +- test/optionsrequest/test.jl | 2 +- test/postform/test.jl | 2 +- test/responses/test.jl | 2 +- test/tests_AppServer.jl | 6 +++--- test/tests_Sessions.jl | 2 +- test/tests_config.jl | 4 ++-- test/tests_content_negotiation.jl | 20 ++++++++++---------- test/tests_fullstack_app.jl | 1 + test/tests_genie_generators.jl | 16 +++++++++++++++- 23 files changed, 65 insertions(+), 39 deletions(-) diff --git a/src/AppServer.jl b/src/AppServer.jl index 17c45d415..5dbf2e28b 100755 --- a/src/AppServer.jl +++ b/src/AppServer.jl @@ -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) @@ -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 diff --git a/src/Configuration.jl b/src/Configuration.jl index fb01169f4..e708014bd 100755 --- a/src/Configuration.jl +++ b/src/Configuration.jl @@ -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_") """ diff --git a/src/Generator.jl b/src/Generator.jl index c12dad81e..8e2bf5dfc 100755 --- a/src/Generator.jl +++ b/src/Generator.jl @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/src/Genie.jl b/src/Genie.jl index ee2379608..e7bbfd1e1 100755 --- a/src/Genie.jl +++ b/src/Genie.jl @@ -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 """ diff --git a/test/cors/cors.jl b/test/cors/cors.jl index 2a02e587a..bd7b77f99 100644 --- a/test/cors/cors.jl +++ b/test/cors/cors.jl @@ -10,4 +10,4 @@ route("/random", method=POST) do (:random => rand(dim,num)) |> json end -up() \ No newline at end of file +up(; open_browser = false) \ No newline at end of file diff --git a/test/fileuploads/test.jl b/test/fileuploads/test.jl index 1b2cc0fdb..4b72d2476 100644 --- a/test/fileuploads/test.jl +++ b/test/fileuploads/test.jl @@ -27,4 +27,4 @@ route("/", method = POST) do @params(:greeting) end -Genie.AppServer.startup(async = false) +Genie.AppServer.startup(; open_browser = false, async = false) diff --git a/test/getargsparse/test.jl b/test/getargsparse/test.jl index a9a881952..f20d84802 100644 --- a/test/getargsparse/test.jl +++ b/test/getargsparse/test.jl @@ -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") diff --git a/test/headers/test.jl b/test/headers/test.jl index be9cc16a6..12ce611f1 100644 --- a/test/headers/test.jl +++ b/test/headers/test.jl @@ -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 diff --git a/test/hello/perftest.jl b/test/hello/perftest.jl index eb67dbcab..449b7160d 100644 --- a/test/hello/perftest.jl +++ b/test/hello/perftest.jl @@ -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) diff --git a/test/hello/test.jl b/test/hello/test.jl index 24285a1d1..b155ce25e 100644 --- a/test/hello/test.jl +++ b/test/hello/test.jl @@ -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") diff --git a/test/htmlrendering/test.jl b/test/htmlrendering/test.jl index 07a70da68..161a2dccc 100644 --- a/test/htmlrendering/test.jl +++ b/test/htmlrendering/test.jl @@ -10,4 +10,4 @@ route("/") do html(markup) end -Genie.AppServer.startup(async = false) +Genie.AppServer.startup(; open_browser = false, async = false) diff --git a/test/inlinecache/test.jl b/test/inlinecache/test.jl index b90c3ed17..c35690ce0 100644 --- a/test/inlinecache/test.jl +++ b/test/inlinecache/test.jl @@ -15,4 +15,4 @@ route("/test") do "All good" end -Genie.AppServer.startup(async = true) +Genie.AppServer.startup(; open_browser = false, async = true) diff --git a/test/json-error/test.jl b/test/json-error/test.jl index 466d8cb6c..9e6e28f4b 100644 --- a/test/json-error/test.jl +++ b/test/json-error/test.jl @@ -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"}""") diff --git a/test/jsonpayload/test.jl b/test/jsonpayload/test.jl index 30214e088..c778d07b8 100644 --- a/test/jsonpayload/test.jl +++ b/test/jsonpayload/test.jl @@ -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"}""") diff --git a/test/optionsrequest/test.jl b/test/optionsrequest/test.jl index fee3ef67d..242dfc286 100644 --- a/test/optionsrequest/test.jl +++ b/test/optionsrequest/test.jl @@ -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 diff --git a/test/postform/test.jl b/test/postform/test.jl index 69278cbb6..30b83258c 100644 --- a/test/postform/test.jl +++ b/test/postform/test.jl @@ -24,4 +24,4 @@ route("/", method = POST) do @params(:greeting) end -Genie.AppServer.startup(async = false) +Genie.AppServer.startup(; open_browser = false, async = false) diff --git a/test/responses/test.jl b/test/responses/test.jl index 6b78bc716..ecd8c9782 100644 --- a/test/responses/test.jl +++ b/test/responses/test.jl @@ -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 diff --git a/test/tests_AppServer.jl b/test/tests_AppServer.jl index f4374ba91..3b196e5bf 100644 --- a/test/tests_AppServer.jl +++ b/test/tests_AppServer.jl @@ -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 @@ -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 @@ -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 diff --git a/test/tests_Sessions.jl b/test/tests_Sessions.jl index 4ca92e140..6742f9dc5 100644 --- a/test/tests_Sessions.jl +++ b/test/tests_Sessions.jl @@ -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") diff --git a/test/tests_config.jl b/test/tests_config.jl index 1964fad44..807707c2e 100644 --- a/test/tests_config.jl +++ b/test/tests_config.jl @@ -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" @@ -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" diff --git a/test/tests_content_negotiation.jl b/test/tests_content_negotiation.jl index d590ad01a..f0aa9ccc6 100644 --- a/test/tests_content_negotiation.jl +++ b/test/tests_content_negotiation.jl @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) @@ -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"]) diff --git a/test/tests_fullstack_app.jl b/test/tests_fullstack_app.jl index c6657adca..26778a3e9 100644 --- a/test/tests_fullstack_app.jl +++ b/test/tests_fullstack_app.jl @@ -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 diff --git a/test/tests_genie_generators.jl b/test/tests_genie_generators.jl index 9da1daa8f..f3d51c708 100644 --- a/test/tests_genie_generators.jl +++ b/test/tests_genie_generators.jl @@ -1,4 +1,4 @@ -@testset "Create new app" begin +@safetestset "Create new app" begin testdir = pwd() using Pkg @@ -9,6 +9,8 @@ workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newapp(workdir, autostart = false, testmode = true) @test true === true @@ -39,6 +41,8 @@ workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newapp(workdir, autostart = false, testmode = true) @test sort(readdir(workdir)) == sort([".gitattributes", ".gitignore", "Manifest.toml", "Project.toml", "bin", @@ -58,6 +62,8 @@ workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newapp(workdir, autostart = false, dbsupport = true, testmode = true) @test sort(readdir(workdir)) == sort([".gitattributes", ".gitignore", "Manifest.toml", "Project.toml", "bin", @@ -76,6 +82,8 @@ workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newapp(workdir, autostart = false, mvcsupport = true, testmode = true) @test sort(readdir(workdir)) == sort([".gitattributes", ".gitignore", "Manifest.toml", "Project.toml", "app", "bin", "bootstrap.jl", "config", "genie.jl", "public", "routes.jl", "src"]) @@ -92,7 +100,9 @@ using Genie workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.Generator.newcontroller("Yazoo") @test isdir(joinpath(workdir, "app", "resources", "yazoo")) == true @@ -107,7 +117,9 @@ using Genie workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newresource("Kazoo") @test isdir(joinpath(workdir, "app", "resources", "kazoo")) == true @@ -123,7 +135,9 @@ using Genie, Genie.Exceptions workdir = Base.Filesystem.mktempdir() + cd(workdir) + Genie.newtask("Vavoom") @test isdir(joinpath(workdir, "tasks")) == true