test(agent): end-to-end Diagnostics test with running Writer
This commit is contained in:
parent
896044cb7f
commit
1f0ab6dd1e
1 changed files with 36 additions and 0 deletions
|
|
@ -61,4 +61,40 @@ defmodule ProxmoxAgent.DiagnosticsTest do
|
||||||
assert :ok = Diagnostics.log_command("zpool", ["list"], {:ok, "body"}, 1_234)
|
assert :ok = Diagnostics.log_command("zpool", ["list"], {:ok, "body"}, 1_234)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "log_command/4 and log_sample/2 with writer running" do
|
||||||
|
setup do
|
||||||
|
dir = Path.join(System.tmp_dir!(), "diag-e2e-#{System.unique_integer([:positive])}")
|
||||||
|
File.mkdir_p!(dir)
|
||||||
|
:ok = Diagnostics.configure(dir)
|
||||||
|
|
||||||
|
{:ok, pid} = ProxmoxAgent.Diagnostics.Writer.start_link(dir: dir)
|
||||||
|
|
||||||
|
on_exit(fn ->
|
||||||
|
if Process.alive?(pid), do: GenServer.stop(pid)
|
||||||
|
File.rm_rf(dir)
|
||||||
|
end)
|
||||||
|
|
||||||
|
%{dir: dir}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "log_command/4 writes to commands.log", %{dir: dir} do
|
||||||
|
assert :ok = Diagnostics.log_command("zpool", ["list", "-j"], {:ok, "body"}, 2_500)
|
||||||
|
:ok = GenServer.call(ProxmoxAgent.Diagnostics.Writer, :flush)
|
||||||
|
|
||||||
|
body = File.read!(Path.join(dir, "commands.log"))
|
||||||
|
assert body =~ "$ zpool list -j"
|
||||||
|
assert body =~ "exit=0"
|
||||||
|
assert body =~ "size=4"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "log_sample/2 writes to samples.log", %{dir: dir} do
|
||||||
|
assert :ok = Diagnostics.log_sample("fast", %{"zfs_pools" => %{"pools" => []}})
|
||||||
|
:ok = GenServer.call(ProxmoxAgent.Diagnostics.Writer, :flush)
|
||||||
|
|
||||||
|
body = File.read!(Path.join(dir, "samples.log"))
|
||||||
|
assert body =~ "kind=fast"
|
||||||
|
assert body =~ "\"zfs_pools\""
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue