feat(server): host detail LiveView with metrics/pools/snapshots/storage/vms

This commit is contained in:
Carsten 2026-04-21 22:53:57 +02:00
parent d0507f290e
commit d65832964e
2 changed files with 342 additions and 0 deletions

View file

@ -0,0 +1,84 @@
defmodule ServerWeb.HostDetailLiveTest do
use ServerWeb.ConnCase, async: false
import Phoenix.LiveViewTest
alias Server.{Hosts, Metrics}
defp auth(conn), do: Plug.Test.init_test_session(conn, %{authenticated: true})
setup do
{:ok, {host, _}} = Hosts.create_host("pve-01")
{:ok, _} = Hosts.mark_online(host, "0.1.0")
fast = %{
"host" => %{"load1" => 0.25, "load5" => 0.3, "load15" => 0.4},
"zfs_pools" => %{
"pools" => [
%{
"name" => "rpool",
"health" => "ONLINE",
"capacity_percent" => 40,
"error_count" => 0,
"last_scrub_end" => "Sat Apr 19 02:00:00 2026"
}
]
},
"storage" => %{
"storages" => [
%{"name" => "local", "type" => "dir", "used_bytes" => 10, "total_bytes" => 100}
]
},
"vms_runtime" => %{
"vms" => [%{"vmid" => 100, "name" => "nginx", "type" => "qemu", "status" => "running"}]
}
}
medium = %{
"zfs_datasets" => %{
"datasets" => [
%{
"name" => "rpool/data",
"snapshot_count" => 2,
"newest_snapshot_unix" => 1_745_193_600,
"oldest_snapshot_unix" => 1_745_107_200
}
]
},
"vms_detail" => %{"vms" => []}
}
slow = %{
"system_info" => %{
"pve_version" => "pve-manager/8.3.1",
"zfs_version" => "zfs-2.3.0",
"pending_updates" => 0
}
}
{:ok, _} = Metrics.record_sample(host.id, "fast", DateTime.utc_now(), fast)
{:ok, _} = Metrics.record_sample(host.id, "medium", DateTime.utc_now(), medium)
{:ok, _} = Metrics.record_sample(host.id, "slow", DateTime.utc_now(), slow)
%{host: host}
end
test "renders sections for metrics, pools, snapshots, storage, VMs", %{
conn: conn,
host: host
} do
{:ok, _view, html} = live(auth(conn), ~p"/hosts/#{host.name}")
assert html =~ "pve-01"
assert html =~ "pve-manager/8.3.1"
assert html =~ "rpool"
assert html =~ "ONLINE"
assert html =~ "nginx"
assert html =~ "rpool/data"
assert html =~ "local"
end
test "404 for unknown host", %{conn: conn} do
assert {:error, {:live_redirect, %{to: "/"}}} =
live(auth(conn), ~p"/hosts/unknown")
end
end