Show a dynamically updated list of NTS servers #1

Merged
mike merged 21 commits from liveview into main 2024-07-26 09:35:19 -04:00
1 changed files with 99 additions and 0 deletions
Showing only changes of commit fbd29d3946 - Show all commits

View File

@ -67,6 +67,105 @@ defmodule Chronoscope.NTSTest do
end end
end end
describe "Chronoscope.NTS.start_client()" do
test "starts a client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [] end)
DynamicSupervisorMock
|> expect(
:start_child,
fn Chronoscope.NTS.DynamicSupervisor,
{Chronoscope.NTS.Client,
[
server: %{host: "test", port: 1},
name: {:via, RegistryMock, {Chronoscope.NTS.Registry, "test:1"}}
]} ->
{:ok, 2}
end
)
assert NTS.start_client(%{host: "test", port: 1}) == 2
end
test "returns an existing client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [{1, nil}] end)
assert NTS.start_client(%{host: "test", port: 1}) == 1
end
end
describe "Chronoscope.NTS.auto_refresh()" do
test "sets up auto refresh for a new client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [] end)
DynamicSupervisorMock
|> expect(
:start_child,
fn Chronoscope.NTS.DynamicSupervisor,
{Chronoscope.NTS.Client,
[
server: %{host: "test", port: 1},
name: {:via, RegistryMock, {Chronoscope.NTS.Registry, "test:1"}}
]} ->
{:ok, 2}
end
)
GenServerMock
|> expect(:call, fn 2, :auto_refresh, 10_000 -> :ok end)
assert NTS.auto_refresh(%{host: "test", port: 1}) == :ok
end
test "sets up auto refresh for an existing client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [{2, nil}] end)
GenServerMock
|> expect(:call, fn 2, :auto_refresh, 10_000 -> :ok end)
assert NTS.auto_refresh(%{host: "test", port: 1}) == :ok
end
end
describe "Chronoscope.NTS.cancel_auto_refresh()" do
test "cancels auto refresh for a new client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [] end)
DynamicSupervisorMock
|> expect(
:start_child,
fn Chronoscope.NTS.DynamicSupervisor,
{Chronoscope.NTS.Client,
[
server: %{host: "test", port: 1},
name: {:via, RegistryMock, {Chronoscope.NTS.Registry, "test:1"}}
]} ->
{:ok, 2}
end
)
GenServerMock
|> expect(:call, fn 2, :cancel_auto_refresh, 10_000 -> :ok end)
assert NTS.cancel_auto_refresh(%{host: "test", port: 1}) == :ok
end
test "cancels auto refresh for an existing client" do
RegistryMock
|> expect(:lookup, fn _, "test:1" -> [{2, nil}] end)
GenServerMock
|> expect(:call, fn 2, :cancel_auto_refresh, 10_000 -> :ok end)
assert NTS.cancel_auto_refresh(%{host: "test", port: 1}) == :ok
end
end
describe "Chronoscope.NTS.remove()" do describe "Chronoscope.NTS.remove()" do
test "does nothing if the client doesn't exist" do test "does nothing if the client doesn't exist" do
RegistryMock RegistryMock