103 lines
3.1 KiB
Elixir
103 lines
3.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}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"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"
|
|
end
|
|
|
|
test "404 for unknown host", %{conn: conn} do
|
|
assert {:error, {:live_redirect, %{to: "/"}}} =
|
|
live(auth(conn), ~p"/hosts/unknown")
|
|
end
|
|
end
|