36 lines
1.1 KiB
Elixir
36 lines
1.1 KiB
Elixir
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
|