feat(agent): Shell.run wrapper for testable external commands
This commit is contained in:
parent
30b507ba6b
commit
6fca450d7e
2 changed files with 43 additions and 0 deletions
19
agent/test/proxmox_agent/shell_test.exs
Normal file
19
agent/test/proxmox_agent/shell_test.exs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
defmodule ProxmoxAgent.ShellTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias ProxmoxAgent.Shell
|
||||
|
||||
test "run/2 returns {:ok, output} on zero exit" do
|
||||
assert {:ok, output} = Shell.run("/bin/echo", ["hello"])
|
||||
assert String.trim(output) == "hello"
|
||||
end
|
||||
|
||||
test "run/2 returns {:error, {:nonzero_exit, code, output}} on non-zero exit" do
|
||||
assert {:error, {:nonzero_exit, code, _}} = Shell.run("/bin/sh", ["-c", "exit 7"])
|
||||
assert code == 7
|
||||
end
|
||||
|
||||
test "run/2 returns {:error, {:enoent, _}} when binary is missing" do
|
||||
assert {:error, {:enoent, _}} = Shell.run("/does/not/exist/nope", [])
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue