Skip to content

Commit 7217223

Browse files
committed
Fix test, return status, job, graph on run
1 parent 7c0d405 commit 7217223

4 files changed

Lines changed: 43 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ erl_crash.dump
2323
imageflow_ex-*.tar
2424

2525
native/imageflow_ex/target/
26+
priv/

lib/imageflow/graph.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ defmodule Imageflow.Graph do
355355
GraphRunner.run(graph)
356356
end
357357

358+
def get_results(job, graph), do: GraphRunner.get_results(job, graph)
359+
358360
defp add_input(%{io_count: io_count, inputs: inputs} = graph, io_id, value) do
359361
%{graph | io_count: io_count + 1, inputs: Map.put(inputs, io_id, value)}
360362
end

lib/imageflow/graph_runner.ex

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Imageflow.GraphRunner do
77
:ok <- add_outputs(job, graph.outputs),
88
:ok <- send_task(job, graph),
99
:ok <- save_outputs(job, graph.outputs) do
10-
{:ok, job}
10+
{:ok, job, graph}
1111
end
1212
end
1313

@@ -52,13 +52,10 @@ defmodule Imageflow.GraphRunner do
5252
defp add_outputs(job, inputs) do
5353
inputs
5454
|> Enum.reduce_while(:ok, fn
55-
{id, value}, :ok ->
56-
case value do
57-
{:file, _path} -> Native.add_output_buffer(job, id)
58-
:bytes -> Native.add_output_buffer(job, id)
59-
end
60-
|> case do
61-
:ok -> {:cont, :ok}
55+
{id, _}, :ok ->
56+
with :ok <- Native.add_output_buffer(job, id) do
57+
{:cont, :ok}
58+
else
6259
{:error, _} = error -> {:halt, error}
6360
end
6461
end)

test/integration/graph_test.exs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
defmodule Imageflow.Integration.GraphTest do
22
use ExUnit.Case
33

4-
alias Imageflow.{Graph, Native}
4+
alias Imageflow.{Graph, Native, Result}
55

66
@input_path "test/fixtures/elixir-logo.jpg"
77
@output_path "/tmp/output.png"
88

99
test "can pipe multiple operations" do
10-
assert :ok =
11-
Graph.new()
12-
|> Graph.decode_file(@input_path)
13-
|> Graph.constrain(20, 20)
14-
|> Graph.rotate_270()
15-
|> Graph.transpose()
16-
|> Graph.color_filter("invert")
17-
|> Graph.encode_to_file(@output_path)
18-
|> Graph.run()
10+
run_result =
11+
Graph.new()
12+
|> Graph.decode_file(@input_path)
13+
|> Graph.constrain(20, 20)
14+
|> Graph.rotate_270()
15+
|> Graph.transpose()
16+
|> Graph.color_filter("invert")
17+
|> Graph.encode_to_file(@output_path)
18+
|> Graph.run()
19+
20+
assert match?({:ok, _job, _graph}, run_result)
1921
end
2022

2123
test "can generate multiple images" do
@@ -47,12 +49,28 @@ defmodule Imageflow.Integration.GraphTest do
4749
end
4850

4951
test "can handle multiple operations" do
50-
assert :ok =
51-
Graph.new()
52-
|> Graph.decode_file(@input_path)
53-
|> Graph.flip_vertical()
54-
|> Graph.transpose()
55-
|> Graph.encode_to_file("/tmp/rotated.png")
56-
|> Graph.run()
52+
run_result =
53+
Graph.new()
54+
|> Graph.decode_file(@input_path)
55+
|> Graph.flip_vertical()
56+
|> Graph.transpose()
57+
|> Graph.encode_to_file("/tmp/rotated.png")
58+
|> Graph.run()
59+
60+
assert match?({:ok, _job, _graph}, run_result)
61+
end
62+
63+
test "can encode to file" do
64+
{:ok, job, graph} =
65+
Graph.new()
66+
|> Graph.decode_file(@input_path)
67+
|> Graph.flip_vertical()
68+
|> Graph.transpose()
69+
|> Graph.encode_to_string()
70+
|> Graph.run()
71+
72+
{:ok, %Result{} = results} = Graph.get_results(job, graph)
73+
74+
assert is_bitstring(results.output)
5775
end
5876
end

0 commit comments

Comments
 (0)