expected v0.1.1 Expected.Store behaviour View Source

Specification for login stores.

To automatically generate tests for a new store, you can use Expected.Store.Test.

Link to this section Summary

Callbacks

Cleans all the logins that have not been used for more than max_age

Deletes a login from the store given its username and serial

Gets the login for the given username and serial from the store

Initialises the store

Lists the logins present in the store for the given username

Puts a login in the store

Link to this section Callbacks

Link to this callback clean_old_logins(max_age, opts) View Source
clean_old_logins(max_age :: integer(), opts :: term()) :: [Expected.Login.t()]

Cleans all the logins that have not been used for more than max_age.

This callback must compare with the :last_login field, not :created_at.

Link to this callback delete(username, serial, opts) View Source
delete(username :: String.t(), serial :: String.t(), opts :: term()) :: :ok

Deletes a login from the store given its username and serial.

Link to this callback get(username, serial, opts) View Source
get(username :: String.t(), serial :: String.t(), opts :: term()) ::
  {:ok, Expected.Login.t()} |
  {:error, :no_login}

Gets the login for the given username and serial from the store.

Link to this callback init(opts) View Source
init(opts :: keyword()) :: term()

Initialises the store.

The value returned from this callback is passed as the last argument to list_user_logins/2, get/3, put/2 and delete/3.

Link to this callback list_user_logins(username, opts) View Source
list_user_logins(username :: String.t(), opts :: term()) :: [Expected.Login.t()]

Lists the logins present in the store for the given username.

Link to this callback put(login, opts) View Source
put(login :: Expected.Login.t(), opts :: term()) :: :ok

Puts a login in the store.

This callback must:

  • create a new entry if there is none for the username and serial,
  • replace the entry if there is already one for the username and serial.

In other words, the couple {username, serial} must be unique.