Add Plug to changelog & format
This commit is contained in:
parent
91fdf2303b
commit
5b0bf83052
3 changed files with 79 additions and 14 deletions
|
@ -13,6 +13,7 @@ The format is based on [Keep a Changelog][1], and this project adheres to [Seman
|
||||||
|
|
||||||
- Forked gen_magic.
|
- Forked gen_magic.
|
||||||
- Pool: `Majic.Pool`
|
- Pool: `Majic.Pool`
|
||||||
|
- Plug: `Majic.Plug`
|
||||||
- Unified API: `Majic.perform/1,2,3`
|
- Unified API: `Majic.perform/1,2,3`
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|
52
test/builds-sr-ht.exs
Normal file
52
test/builds-sr-ht.exs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
name =
|
||||||
|
case System.cmd("git", ~w(describe --all --long --dirty --broken --always)) do
|
||||||
|
{name, 0} -> String.trim(name)
|
||||||
|
_ -> "cannot-git-describe"
|
||||||
|
end
|
||||||
|
|
||||||
|
repo = System.get_env("TEST_REPO") || "https://git.sr.ht/~href/gen_magic"
|
||||||
|
|
||||||
|
IO.puts("Using repository: #{repo}")
|
||||||
|
|
||||||
|
token = System.get_env("SR_HT_TOKEN")
|
||||||
|
|
||||||
|
unless token do
|
||||||
|
IO.puts("""
|
||||||
|
sr.ht token not defined (SR_HT_TOKEN)\n\n
|
||||||
|
Get one at https://meta.sr.ht/oauth/personal-token\n
|
||||||
|
Define one by setting the SR_HT_TOKEN environment variable
|
||||||
|
""")
|
||||||
|
else
|
||||||
|
Application.ensure_all_started(:ssl)
|
||||||
|
Application.ensure_all_started(:inets)
|
||||||
|
|
||||||
|
File.ls!(".builds")
|
||||||
|
|> Enum.filter(fn file -> Path.extname(file) == ".yaml" end)
|
||||||
|
|> Enum.each(fn file ->
|
||||||
|
file = Path.join(".builds", file)
|
||||||
|
build = Path.basename(file, ".yaml")
|
||||||
|
|
||||||
|
build =
|
||||||
|
%{
|
||||||
|
"manifest" => File.read!(file),
|
||||||
|
"note" => "gen_magic/#{name} #{build}",
|
||||||
|
"tags" => ["gen_magic"]
|
||||||
|
}
|
||||||
|
|> Jason.encode!()
|
||||||
|
|
||||||
|
case :httpc.request(
|
||||||
|
:post,
|
||||||
|
{'https://builds.sr.ht/api/jobs', [{'authorization', 'token ' ++ to_charlist(token)}],
|
||||||
|
'application/json', build},
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
) do
|
||||||
|
{:ok, {{_http_v, 200, 'OK'}, _headers, body}} ->
|
||||||
|
resp = Jason.decode!(body)
|
||||||
|
IO.puts("#{resp["status"]} job #{resp["note"]}, id: #{resp["id"]}")
|
||||||
|
|
||||||
|
error ->
|
||||||
|
IO.puts("Failed to enqueue job #{inspect(error)}")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
|
@ -5,11 +5,14 @@ defmodule Majic.PlugTest do
|
||||||
defmodule TestRouter do
|
defmodule TestRouter do
|
||||||
use Plug.Router
|
use Plug.Router
|
||||||
|
|
||||||
plug :match
|
plug(:match)
|
||||||
plug :dispatch
|
plug(:dispatch)
|
||||||
plug Plug.Parsers,
|
|
||||||
|
plug(Plug.Parsers,
|
||||||
parsers: [:urlencoded, :multipart],
|
parsers: [:urlencoded, :multipart],
|
||||||
pass: ["*/*"]
|
pass: ["*/*"]
|
||||||
|
)
|
||||||
|
|
||||||
# plug Majic.Plug, once: true
|
# plug Majic.Plug, once: true
|
||||||
|
|
||||||
post "/" do
|
post "/" do
|
||||||
|
@ -44,13 +47,14 @@ defmodule Majic.PlugTest do
|
||||||
------w58EW1cEpjzydSCq--\r
|
------w58EW1cEpjzydSCq--\r
|
||||||
"""
|
"""
|
||||||
|
|
||||||
orig_conn = conn(:post, "/", multipart)
|
orig_conn =
|
||||||
|
conn(:post, "/", multipart)
|
||||||
|> put_req_header("content-type", "multipart/mixed; boundary=----w58EW1cEpjzydSCq")
|
|> put_req_header("content-type", "multipart/mixed; boundary=----w58EW1cEpjzydSCq")
|
||||||
|> TestRouter.call(@router_opts)
|
|> TestRouter.call(@router_opts)
|
||||||
|
|
||||||
plug = Majic.Plug.init([once: true])
|
plug = Majic.Plug.init(once: true)
|
||||||
plug_no_ext = Majic.Plug.init([once: true, fix_extension: false])
|
plug_no_ext = Majic.Plug.init(once: true, fix_extension: false)
|
||||||
plug_append_ext = Majic.Plug.init([once: true, fix_extension: true, append_extension: true])
|
plug_append_ext = Majic.Plug.init(once: true, fix_extension: true, append_extension: true)
|
||||||
|
|
||||||
conn = Majic.Plug.call(orig_conn, plug)
|
conn = Majic.Plug.call(orig_conn, plug)
|
||||||
conn_no_ext = Majic.Plug.call(orig_conn, plug_no_ext)
|
conn_no_ext = Majic.Plug.call(orig_conn, plug_no_ext)
|
||||||
|
@ -58,15 +62,23 @@ defmodule Majic.PlugTest do
|
||||||
|
|
||||||
assert conn.state == :sent
|
assert conn.state == :sent
|
||||||
assert conn.status == 200
|
assert conn.status == 200
|
||||||
refute get_in(conn.body_params, ["form", "makefile"]).content_type == get_in(conn.params, ["form", "makefile"]).content_type
|
|
||||||
|
refute get_in(conn.body_params, ["form", "makefile"]).content_type ==
|
||||||
|
get_in(conn.params, ["form", "makefile"]).content_type
|
||||||
|
|
||||||
assert get_in(conn.params, ["form", "makefile"]).content_type == "text/x-makefile"
|
assert get_in(conn.params, ["form", "makefile"]).content_type == "text/x-makefile"
|
||||||
refute get_in(conn.body_params, ["form", "make", "file"]).content_type == get_in(conn.params, ["form", "make", "file"]).content_type
|
|
||||||
|
refute get_in(conn.body_params, ["form", "make", "file"]).content_type ==
|
||||||
|
get_in(conn.params, ["form", "make", "file"]).content_type
|
||||||
|
|
||||||
assert get_in(conn.params, ["form", "make", "file"]).content_type == "text/x-makefile"
|
assert get_in(conn.params, ["form", "make", "file"]).content_type == "text/x-makefile"
|
||||||
refute get_in(conn.body_params, ["cat"]).content_type == get_in(conn.params, ["cat"]).content_type
|
|
||||||
|
refute get_in(conn.body_params, ["cat"]).content_type ==
|
||||||
|
get_in(conn.params, ["cat"]).content_type
|
||||||
|
|
||||||
assert get_in(conn.params, ["cat"]).content_type == "image/webp"
|
assert get_in(conn.params, ["cat"]).content_type == "image/webp"
|
||||||
assert get_in(conn.params, ["cat"]).filename == "cute-cat.webp"
|
assert get_in(conn.params, ["cat"]).filename == "cute-cat.webp"
|
||||||
assert get_in(conn_no_ext.params, ["cat"]).filename == "cute-cat.jpg"
|
assert get_in(conn_no_ext.params, ["cat"]).filename == "cute-cat.jpg"
|
||||||
assert get_in(conn_append_ext.params, ["cat"]).filename == "cute-cat.jpg.webp"
|
assert get_in(conn_append_ext.params, ["cat"]).filename == "cute-cat.jpg.webp"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue