Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kidq330 committed Jan 9, 2024
1 parent 5a4ceec commit 002f3e0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 48 deletions.
48 changes: 0 additions & 48 deletions test/integration/source_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,4 @@ defmodule Membrane.File.Integration.SourceTest do
assert_sink_buffer(pipeline_pid, :sink, %Buffer{payload: "01234"})
assert_end_of_stream(pipeline_pid, :sink)
end

@tmp_output "/tmp/output.txt"

@tag :mustexec
# @tag timeout: :infinity
test "pipeline from :stdin to file works" do
assert {"", _rc = 0} =
System.cmd(
"bash",
[
"-c",
"set -o pipefail; cat #{@input_text_file} | mix run test/fixtures/pipe_to_file.exs #{@tmp_output} 1024"
],
env: [{"MIX_QUIET", "true"}]
)

assert "0123456789" == File.read!(@tmp_output)
end

@tag :mustexec
# @tag timeout: :infinity
test "pipeline from file to :stdout works" do
assert {"0123456789", _rc = 0} =
System.cmd(
"bash",
[
"-c",
"mix run test/fixtures/file_to_pipe.exs #{@input_text_file}"
],
env: [{"MIX_QUIET", "true"}]
)
end

@tag :mustexec
# @tag timeout: :infinity
test ":stdin/:stdout pipelines work in conjunction" do
assert {"", _rc = 0} =
System.cmd(
"bash",
[
"-c",
"set -o pipefail; mix run test/fixtures/file_to_pipe.exs #{@input_text_file} | mix run test/fixtures/pipe_to_file.exs #{@tmp_output} 1024"
],
env: [{"MIX_QUIET", "true"}]
)

assert "0123456789" == File.read!(@tmp_output)
end
end
76 changes: 76 additions & 0 deletions test/integration/stdio_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
defmodule Membrane.File.Integration.StdioTest do
use ExUnit.Case, async: false
@moduletag timeout: 360_000

require Logger

@input_text_file "test/fixtures/input.txt"
@cmd_out_prefix "/tmp/membrane_file_test_out"
@cmd_err_prefix "/tmp/membrane_file_test_err"

setup_all(_context) do
assert Mix.Task.run("compile", ["test/fixtures/*.exs"]) in [:ok, :noop]
:ok
end

setup(%{line: line} = _context) do
cmd_out_file = @cmd_out_prefix <> Integer.to_string(line) <> ".log"
cmd_err_file = @cmd_err_prefix <> Integer.to_string(line) <> ".log"
{:ok, %{cmd_out: cmd_out_file, cmd_err: cmd_err_file}}
end

test "pipeline from :stdin to file works",
%{cmd_out: cmd_out, cmd_err: cmd_err} = _context do
assert {"", _rc = 0} ==
System.shell(
"bash -c ' \
set -o pipefail; \
cat #{@input_text_file} | mix run test/fixtures/pipe_to_file.exs #{cmd_out} 2048' \
2> #{cmd_err}",
env: [{"MIX_QUIET", "true"}]
)

Logger.debug(File.read!(cmd_err))
assert "0123456789" == File.read!(cmd_out)
end

test "pipeline from :stdin to file works when content is longer than chunk_size",
%{cmd_out: cmd_out, cmd_err: cmd_err} = _context do
assert {"", _rc = 0} ==
System.shell(
"bash -c ' \
set -o pipefail; \
cat #{@input_text_file} | mix run test/fixtures/pipe_to_file.exs #{cmd_out} 5' \
2> #{cmd_err}",
env: [{"MIX_QUIET", "true"}]
)

Logger.debug(File.read!(cmd_err))
assert "0123456789" == File.read!(cmd_out)
end

test "pipeline from file to :stdout works",
%{cmd_err: cmd_err} = _context do
assert {"0123456789", _rc = 0} ==
System.shell("mix run test/fixtures/file_to_pipe.exs #{@input_text_file} \
2> #{cmd_err}",
env: [{"MIX_QUIET", "true"}]
)
end

test ":stdin/:stdout pipelines work in conjunction",
%{cmd_out: cmd_out, cmd_err: cmd_err} = _context do
assert {"", _rc = 0} ==
System.shell(
"bash -c ' \
set -o pipefail; \
mix run test/fixtures/file_to_pipe.exs #{@input_text_file} \
| mix run test/fixtures/pipe_to_file.exs #{cmd_out} 2048' \
2> #{cmd_err}",
env: [{"MIX_QUIET", "true"}]
)

Logger.debug(File.read!(cmd_err))
assert "0123456789" == File.read!(cmd_out)
end
end

0 comments on commit 002f3e0

Please sign in to comment.