feat(server): vm search LiveView with name+IP filtering
This commit is contained in:
parent
d65832964e
commit
94034eea9b
2 changed files with 175 additions and 0 deletions
71
server/test/server_web/live/vm_search_live_test.exs
Normal file
71
server/test/server_web/live/vm_search_live_test.exs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue