proxMon/server/test/server_web/live/vm_search_live_test.exs

71 lines
1.8 KiB
Elixir

defmodule ServerWeb.VmSearchLiveTest 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, {h1, _}} = Hosts.create_host("pve-01")
{:ok, {h2, _}} = Hosts.create_host("pve-02")
fast1 = %{
"vms_runtime" => %{
"vms" => [
%{"vmid" => 100, "name" => "nginx-proxy", "type" => "qemu", "status" => "running"}
]
}
}
fast2 = %{
"vms_runtime" => %{
"vms" => [
%{"vmid" => 200, "name" => "db-primary", "type" => "qemu", "status" => "running"}
]
}
}
medium1 = %{
"vms_detail" => %{
"vms" => [%{"vmid" => 100, "name" => "nginx-proxy", "ips" => ["192.168.1.10"]}]
}
}
{:ok, _} = Metrics.record_sample(h1.id, "fast", DateTime.utc_now(), fast1)
{:ok, _} = Metrics.record_sample(h2.id, "fast", DateTime.utc_now(), fast2)
{:ok, _} = Metrics.record_sample(h1.id, "medium", DateTime.utc_now(), medium1)
:ok
end
test "lists all VMs from all hosts by default", %{conn: conn} do
{:ok, _view, html} = live(auth(conn), "/vms")
assert html =~ "nginx-proxy"
assert html =~ "db-primary"
end
test "filters by name substring", %{conn: conn} do
{:ok, view, _html} = live(auth(conn), "/vms")
html =
view
|> form("form", q: "nginx")
|> render_change()
assert html =~ "nginx-proxy"
refute html =~ "db-primary"
end
test "filters by IP substring (matches detail payload)", %{conn: conn} do
{:ok, view, _html} = live(auth(conn), "/vms")
html =
view
|> form("form", q: "192.168.1")
|> render_change()
assert html =~ "nginx-proxy"
refute html =~ "db-primary"
end
end