proxMon/server/test/server_web/live/host_detail_live_test.exs
Carsten dd992573a1 fix(ui): strengthen scrub assertion, cover degraded vdev render path
Addresses code review: differentiate pool_scrub_line/1 FINISHED clause
with the word "finished", test the degraded-vdev callout via a second
DEGRADED pool in the fixture, and replace the generic "scrub" match
with an assertion on the full finished line.
2026-04-22 18:00:13 +02:00

130 lines
4.1 KiB
Elixir

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",
"pool_type" => "mirror",
"size_bytes" => 500_000_000_000,
"allocated_bytes" => 200_000_000_000,
"free_bytes" => 300_000_000_000,
"capacity_percent" => 40,
"fragmentation_percent" => 17,
"error_count" => 0,
"vdev_count" => 1,
"degraded_vdev_count" => 0,
"scan_function" => "scrub",
"scan_state" => "FINISHED",
"last_scrub_end" => "Sat Apr 19 02:00:00 2026",
"vdevs" => [
%{"name" => "mirror-0", "type" => "mirror", "state" => "ONLINE",
"read_errors" => 0, "write_errors" => 0, "checksum_errors" => 0}
]
},
%{
"name" => "tank",
"health" => "DEGRADED",
"pool_type" => "raidz2",
"size_bytes" => 8_000_000_000_000,
"allocated_bytes" => 6_000_000_000_000,
"free_bytes" => 2_000_000_000_000,
"capacity_percent" => 75,
"fragmentation_percent" => 55,
"error_count" => 2,
"vdev_count" => 1,
"degraded_vdev_count" => 1,
"scan_function" => "scrub",
"scan_state" => "SCANNING",
"last_scrub_end" => nil,
"vdevs" => [
%{"name" => "raidz2-0", "type" => "raidz2", "state" => "DEGRADED",
"read_errors" => 0, "write_errors" => 0, "checksum_errors" => 2}
]
}
]
},
"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"
assert html =~ "mirror"
assert html =~ "465.7 GB" # size_bytes formatted
assert html =~ "186.3 GB" # allocated_bytes formatted
assert html =~ "279.4 GB" # free_bytes formatted
assert html =~ "capbar"
assert html =~ "scrub finished Sat Apr 19 02:00:00 2026"
assert html =~ "tank"
assert html =~ "DEGRADED"
assert html =~ "raidz2"
assert html =~ "scrub scanning"
assert html =~ "raidz2-0 DEGRADED"
assert html =~ "cksum=2"
assert html =~ "callout err"
end
test "404 for unknown host", %{conn: conn} do
assert {:error, {:live_redirect, %{to: "/"}}} =
live(auth(conn), ~p"/hosts/unknown")
end
end