36 lines
962 B
Elixir
36 lines
962 B
Elixir
defmodule ServerWeb.HostControllerTest do
|
|
use ServerWeb.ConnCase, async: true
|
|
|
|
alias Server.{Hosts, Metrics}
|
|
|
|
describe "GET /api/hosts/:name" do
|
|
setup do
|
|
{:ok, {host, _token}} = Hosts.create_host("pve-01")
|
|
|
|
{:ok, _} =
|
|
Metrics.record_sample(
|
|
host.id,
|
|
"fast",
|
|
DateTime.utc_now(),
|
|
%{"host" => %{"load1" => 0.5}}
|
|
)
|
|
|
|
%{host: host}
|
|
end
|
|
|
|
test "returns host info and latest samples", %{conn: conn, host: host} do
|
|
conn = get(conn, ~p"/api/hosts/#{host.name}")
|
|
|
|
assert %{
|
|
"name" => "pve-01",
|
|
"status" => _,
|
|
"samples" => %{"fast" => %{"payload" => %{"host" => %{"load1" => 0.5}}}}
|
|
} = json_response(conn, 200)
|
|
end
|
|
|
|
test "returns 404 for unknown host", %{conn: conn} do
|
|
conn = get(conn, ~p"/api/hosts/nope")
|
|
assert json_response(conn, 404) == %{"error" => "host_not_found"}
|
|
end
|
|
end
|
|
end
|