diff --git a/test/chronoscope/nts_test.exs b/test/chronoscope/nts_test.exs index 08b3b25..54aeab6 100644 --- a/test/chronoscope/nts_test.exs +++ b/test/chronoscope/nts_test.exs @@ -1,6 +1,7 @@ defmodule Chronoscope.NTSTest do use Chronoscope.Case + alias Chronoscope.NTS alias Chronoscope.NTS.DynamicSupervisorMock alias Chronoscope.NTS.GenServerMock alias Chronoscope.NTS.RegistryMock @@ -43,5 +44,47 @@ defmodule Chronoscope.NTSTest do assert remove("localhost", 1111) == {:error, :not_found} 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