Add tests
This commit is contained in:
parent
9c3523d9d1
commit
911f19ff09
|
@ -1,6 +1,7 @@
|
||||||
defmodule Chronoscope.NTSTest do
|
defmodule Chronoscope.NTSTest do
|
||||||
use Chronoscope.Case
|
use Chronoscope.Case
|
||||||
|
|
||||||
|
alias Chronoscope.NTS
|
||||||
alias Chronoscope.NTS.DynamicSupervisorMock
|
alias Chronoscope.NTS.DynamicSupervisorMock
|
||||||
alias Chronoscope.NTS.GenServerMock
|
alias Chronoscope.NTS.GenServerMock
|
||||||
alias Chronoscope.NTS.RegistryMock
|
alias Chronoscope.NTS.RegistryMock
|
||||||
|
@ -43,5 +44,47 @@ defmodule Chronoscope.NTSTest do
|
||||||
|
|
||||||
assert remove("localhost", 1111) == {:error, :not_found}
|
assert remove("localhost", 1111) == {:error, :not_found}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "removes a client" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [{1, 2}] end)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 1, :terminate -> :terminating end)
|
||||||
|
|
||||||
|
assert remove("localhost", 1111) == {:ok, :terminating}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Chronoscope.NTS.key_establishment()" do
|
||||||
|
test "creates a new client" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [] end)
|
||||||
|
|
||||||
|
DynamicSupervisorMock
|
||||||
|
|> expect(:start_child, fn NTS.DynamicSupervisor,
|
||||||
|
{NTS.Client,
|
||||||
|
[
|
||||||
|
server: %{host: "localhost", port: 1111},
|
||||||
|
name: {:via, RegistryMock, {NTS.Registry, "localhost:1111"}}
|
||||||
|
]} ->
|
||||||
|
{:ok, 1}
|
||||||
|
end)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 1, :key_establishment -> :result end)
|
||||||
|
|
||||||
|
assert key_establishment("localhost", 1111) == :result
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reuses an existing client" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [{1, 2}] end)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 1, :key_establishment -> :result end)
|
||||||
|
|
||||||
|
assert key_establishment("localhost", 1111) == :result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue