feat(agent): pvesh storage collector

This commit is contained in:
Carsten 2026-04-21 22:33:27 +02:00
parent 8c3e953e4e
commit ec7f08dfda
3 changed files with 108 additions and 0 deletions

View file

@ -0,0 +1,36 @@
defmodule ProxmoxAgent.Collectors.StorageTest do
use ExUnit.Case, async: true
alias ProxmoxAgent.Collectors.Storage
@fixtures Path.expand("../../fixtures/pvesh", __DIR__)
defp fake_runner do
fn
"pvesh", ["get", "/nodes/" <> _, "--output-format", "json"] ->
{:ok, File.read!(Path.join(@fixtures, "storage.json"))}
end
end
test "returns one summary per storage entry" do
sample = Storage.collect(node: "pve-01", runner: fake_runner())
assert length(sample.storages) == 3
local = Enum.find(sample.storages, &(&1.name == "local"))
assert local.type == "dir"
assert local.active == true
assert local.used_bytes == 50_000_000_000
assert local.total_bytes == 500_000_000_000
assert local.content == "backup,iso,vztmpl"
nfs = Enum.find(sample.storages, &(&1.name == "backup-nfs"))
assert nfs.active == false
end
test "populates errors on failure" do
failing = fn _, _ -> {:error, {:enoent, "pvesh"}} end
sample = Storage.collect(node: "pve-01", runner: failing)
assert sample.storages == []
assert sample.errors != []
end
end