Add tests
This commit is contained in:
parent
68fb573d01
commit
a07ce6e410
|
@ -0,0 +1,92 @@
|
||||||
|
defmodule Chronoscope.GeminiTest do
|
||||||
|
use Chronoscope.Case, async: true
|
||||||
|
|
||||||
|
alias Chronoscope.DynamicSupervisorMock
|
||||||
|
alias Chronoscope.GenServerMock
|
||||||
|
alias Chronoscope.Gemini
|
||||||
|
alias Chronoscope.RegistryMock
|
||||||
|
|
||||||
|
import Mox
|
||||||
|
|
||||||
|
setup :verify_on_exit!
|
||||||
|
|
||||||
|
describe "Chronoscope.Gemini.healthy?()" do
|
||||||
|
test "is healthy" do
|
||||||
|
assert Gemini.healthy?() == true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Chronoscope.Gemini.list()" do
|
||||||
|
test "shows empty client list" do
|
||||||
|
DynamicSupervisorMock
|
||||||
|
|> expect(:which_children, fn _ -> [] end)
|
||||||
|
|
||||||
|
assert Gemini.list() == []
|
||||||
|
end
|
||||||
|
|
||||||
|
test "lists all children" do
|
||||||
|
DynamicSupervisorMock
|
||||||
|
|> expect(:which_children, fn _ -> [{1, 2, 3, 4}, {5, 6, 7, 8}] end)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 2, :list -> :one end)
|
||||||
|
|> expect(:call, fn 6, :list -> :two end)
|
||||||
|
|
||||||
|
assert Gemini.list() == [:one, :two]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Chronoscope.Gemini.remove()" do
|
||||||
|
test "does nothing if the client doesn't exist" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [] end)
|
||||||
|
|
||||||
|
assert Gemini.remove("localhost", 1965, "/") == {: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 Gemini.remove("localhost", 1965, "/") == {:ok, :terminating}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Chronoscope.Gemini.connect()" do
|
||||||
|
test "creates a new client" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [] end)
|
||||||
|
|
||||||
|
DynamicSupervisorMock
|
||||||
|
|> expect(
|
||||||
|
:start_child,
|
||||||
|
fn Chronoscope.Gemini.DynamicSupervisor,
|
||||||
|
{Chronoscope.Gemini.Client,
|
||||||
|
[
|
||||||
|
resource: %{host: "localhost", port: 1965, path: "/"},
|
||||||
|
name: {:via, RegistryMock, {Chronoscope.Gemini.Registry, "localhost:1965/"}}
|
||||||
|
]} ->
|
||||||
|
{:ok, 1}
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 1, :connect -> :result end)
|
||||||
|
|
||||||
|
assert Gemini.connect("localhost", 1965, "/") == :result
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reuses an existing client" do
|
||||||
|
RegistryMock
|
||||||
|
|> expect(:lookup, fn _, _ -> [{1, 2}] end)
|
||||||
|
|
||||||
|
GenServerMock
|
||||||
|
|> expect(:call, fn 1, :connect -> :result end)
|
||||||
|
|
||||||
|
assert Gemini.connect("localhost", 1965, "/") == :result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -61,14 +61,17 @@ defmodule Chronoscope.NTSTest do
|
||||||
|> expect(:lookup, fn _, _ -> [] end)
|
|> expect(:lookup, fn _, _ -> [] end)
|
||||||
|
|
||||||
DynamicSupervisorMock
|
DynamicSupervisorMock
|
||||||
|> expect(:start_child, fn Chronoscope.NTS.DynamicSupervisor,
|
|> expect(
|
||||||
|
:start_child,
|
||||||
|
fn Chronoscope.NTS.DynamicSupervisor,
|
||||||
{Chronoscope.NTS.Client,
|
{Chronoscope.NTS.Client,
|
||||||
[
|
[
|
||||||
server: %{host: "localhost", port: 1111},
|
server: %{host: "localhost", port: 1111},
|
||||||
name: {:via, RegistryMock, {Chronoscope.NTS.Registry, "localhost:1111"}}
|
name: {:via, RegistryMock, {Chronoscope.NTS.Registry, "localhost:1111"}}
|
||||||
]} ->
|
]} ->
|
||||||
{:ok, 1}
|
{:ok, 1}
|
||||||
end)
|
end
|
||||||
|
)
|
||||||
|
|
||||||
GenServerMock
|
GenServerMock
|
||||||
|> expect(:call, fn 1, :key_establishment -> :result end)
|
|> expect(:call, fn 1, :key_establishment -> :result end)
|
||||||
|
|
Loading…
Reference in New Issue