Im trying to write some tests for a process that uses the Connection behavior. The tests start to get really complicated. When I call RestConnection the start_link function returns imideatly. Then a connection should be estamblised and a login token recied should be set in the process state. Now I want to assert on three things in the test below wich is a negative case where the connection is down.
I want to assert the following:
- Check error is logged
- Make sure an :EXIT is raised
3: Check the state process state that the token key is not set
What I have so far is an attempt at this that is not working.
test "connection down", %{bypass: bypass} = context do
Bypass.down(bypass)
catch_exit do
output =
capture_log(fn ->
{:ok, _pid} = RestConnection.start_link("user", "pwd", "key")
:timer.sleep(1000)
end)
end
pid = context[:pid]
assert output =~ "[error] Login failed"
assert_received({:EXIT, ^pid, :login_failed})
end