From 1f0ab6dd1ef2cd863e771c803e71d7e2133717aa Mon Sep 17 00:00:00 2001 From: Carsten Date: Wed, 22 Apr 2026 22:21:17 +0200 Subject: [PATCH] test(agent): end-to-end Diagnostics test with running Writer --- agent/test/proxmox_agent/diagnostics_test.exs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/agent/test/proxmox_agent/diagnostics_test.exs b/agent/test/proxmox_agent/diagnostics_test.exs index 867f358..000bfe2 100644 --- a/agent/test/proxmox_agent/diagnostics_test.exs +++ b/agent/test/proxmox_agent/diagnostics_test.exs @@ -61,4 +61,40 @@ defmodule ProxmoxAgent.DiagnosticsTest do assert :ok = Diagnostics.log_command("zpool", ["list"], {:ok, "body"}, 1_234) 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