We are now onto writing the outside in tests.
I have got as far as the first test. This is failing with authentication errors.
[error] Postgrex.Protocol (#PID<0.251.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "chris*****"
iex -S mix came to the rescue here:
h Ecto.Adapters.SQL.Sandbox.checkout Checks a connection out for the given repo. The process calling checkout/2 will own the connection until it calls checkin/2 or until it crashes when then the connection will be automatically reclaimed by the pool. ## Options • :sandbox - when true the connection is wrapped in a transaction. Defaults to true. • :isolation - set the query to the given isolation level. • :ownership_timeout - limits how long the connection can be owned. Defaults to the value in your repo config in config/config.exs (or preferably in config/test.exs), or 60000 ms if not set. The timeout exists for sanity checking purposes, to ensure there is no connection leakage, and can be bumped whenever necessary.
This was the important clue that I had not got my test database configured correctly.
This is the new version of
use Mix.Config config :mastery_persistence, MasteryPersistence.Repo, database: "mastery_test", hostname: "localhost", port: 54320, pool: Ecto.Adapters.SQL.Sandbox, username: "postgres", password: "postgres" config :mastery, :persistence_fn, &Mastery.Persistence.record_response/2
I had “forgotten” the username here.
I now have the persistence tests implemented: https://github.com:chriseyre2000/mastery (dc6c5bf)