Gitility.ODB.RangeBackend.Conformance (Gitility v0.2.0)

Copy Markdown View Source

Reusable ExUnit conformance case for Gitility.ODB.RangeBackend modules.

The using test module supplies backend_init_arg/0, backend_artifacts/0, and backend_publish_artifact/3. The last callback publishes the supplied key and bytes into the initialized test backend. The kit uses it to add a deterministic 2 MiB-plus-17-byte artifact, guaranteeing that its range matrix crosses the Postgres backend's 1 MiB chunk seam without enlarging a repository fixture.

Generated tests validate the manifest protocol, whole/first/last-byte reads, zero-length reads at zero and EOF, a chunk-boundary crossing, multiple keys in one request, out-of-bounds short reads, concurrent callback safety, and tolerant termination.

defmodule MyApp.PackStoreConformanceTest do
  use Gitility.ODB.RangeBackend.Conformance,
    backend: MyApp.PackStore,
    concurrency: 4

  def backend_init_arg, do: [bucket: "test-packs"]
  def backend_artifacts, do: MyApp.PackFixtures.artifacts()
  def backend_publish_artifact(state, key, bytes),
    do: MyApp.PackFixtures.publish_artifact(state, key, bytes)
end

A deliberately broken backend can set expected_failure: :short_read; the generated exactness test then asserts that the conformance validator rejects it. An immutable backend whose fixture already contains synthetic_artifact/0 can set prepublished_synthetic: true. Cases are not async because backend state often owns a connection or temporary directory.