Skip to content

Commit

Permalink
Fix internal error on info operation in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Nov 1, 2023
1 parent fef29cb commit c4718c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/plug_image_processing/operations/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ defmodule PlugImageProcessing.Operations.Info do

alias Vix.Vips.Image

def new(_image, _params, _config) do
{:error, :invalid_operation}
end

defimpl PlugImageProcessing.Info do
def process(operation) do
{:ok,
Expand Down
26 changes: 26 additions & 0 deletions test/plug_image_processing/web_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,31 @@ defmodule PlugImageProcessing.WebTest do
assert image_metadata["has_alpha"] === false
assert image_metadata["channels"] === 3
end

test "pipeline", %{config: config} do
plug_opts = Web.init(config)
conn = conn(:get, "/imageproxy/pipeline", %{operations: Jason.encode!([%{operation: "crop", params: %{width: 20, height: 50}}]), url: "http://example.org/valid.jpg"})
conn = Web.call(conn, plug_opts)

{:ok, image} = conn_to_image(conn)

assert Image.width(image) === 20
assert Image.height(image) === 50
end

test "pipeline info", %{config: config} do
plug_opts = Web.init(config)

conn =
conn(:get, "/imageproxy/pipeline", %{
operations: Jason.encode!([%{operation: "crop", params: %{width: 20, height: 50}}, %{operation: "info"}]),
url: "http://example.org/valid.jpg"
})

conn = Web.call(conn, plug_opts)

assert conn.status === 400
assert conn.resp_body === "Bad request: :invalid_operation"
end
end
end

0 comments on commit c4718c5

Please sign in to comment.