Arke.Test.Persistence (Arke v0.8.0)

Copy Markdown View Source

In-memory implementation of the arke persistence contract, for test suites.

Arke core performs no I/O of its own; a persistence layer is injected through config. This one keeps units in ETS instead of a database, so QueryManager.get_by/1 and friends round-trip what was created and validations that query (uniqueness, duplicate ids) actually work.

# config/test.exs
config :arke,
  persistence: %{
    arke_postgres: %{
      create: &Arke.Test.Persistence.create/2,
      update: &Arke.Test.Persistence.update/2,
      update_key: &Arke.Test.Persistence.update_key/2,
      delete: &Arke.Test.Persistence.delete/2,
      execute_query: &Arke.Test.Persistence.execute/2,
      get_parameters: &Arke.Test.Persistence.get_parameters/0,
      create_project: &Arke.Test.Persistence.create_project/1,
      delete_project: &Arke.Test.Persistence.delete_project/1
    }
  }

Call setup/0 once from test_helper.exs, before any test runs, so the table is owned by a process that outlives them. Arke.Test.Sandbox.restore/0 empties it between tests.

Summary

Functions

Mirrors the repo's insert_all/3; sends the call to the caller for assert_received.

Drops every stored unit.

Creates the backing table. Idempotent.

Mirrors the adapter's update_key/2, which takes the current unit rather than a project so the old row can be replaced when the id changes.

Functions

create(project, unit)

@spec create(atom(), Arke.Core.Unit.t()) :: {:ok, Arke.Core.Unit.t()}

create_project(map)

@spec create_project(Arke.Core.Unit.t()) :: :ok

delete(project, unit)

@spec delete(atom(), Arke.Core.Unit.t()) :: {:ok, nil}

delete_project(map)

@spec delete_project(Arke.Core.Unit.t()) :: :ok

execute(query, atom)

@spec execute(Arke.Core.Query.t(), atom()) :: any()

get_parameters()

@spec get_parameters() :: []

insert_all(table, rows, opts)

@spec insert_all(String.t(), [keyword()], keyword()) :: {non_neg_integer(), nil}

Mirrors the repo's insert_all/3; sends the call to the caller for assert_received.

reset()

@spec reset() :: :ok

Drops every stored unit.

setup()

@spec setup() :: :ok

Creates the backing table. Idempotent.

update(project, unit)

@spec update(atom(), Arke.Core.Unit.t()) :: {:ok, Arke.Core.Unit.t()}

update_key(current_unit, new_unit)

@spec update_key(Arke.Core.Unit.t(), Arke.Core.Unit.t()) :: {:ok, Arke.Core.Unit.t()}

Mirrors the adapter's update_key/2, which takes the current unit rather than a project so the old row can be replaced when the id changes.