Show a dynamically updated list of NTS servers #1
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue