Skip to content
Source on GitHub (opens in a new tab)
import "github.com/barevoidco/zelk/core/lease/leasetest"

Package leasetest is the conformance kit for lease.Lease implementations: zelk’s own leases run it, and so should any lease a host writes (docs/design/durability.md, “Leases and stores”).

The kit drives time itself, through a clock it gives the lease, so its expiry cases take no wall-clock time.

const TTL = 10 * time.Second

TTL is the grant length the kit asks for.

func Run(t *testing.T, f Factory)

Run checks that the leases made by f behave as lease.Lease and the rules in docs/design/durability.md (“Leases and stores”) require.

type Factory func(t *testing.T, now func() time.Time, ttl time.Duration) (open func(t *testing.T) lease.Lease)

Factory sets up one lease’s backing state, with grants timed by now and lasting ttl, and returns a function that opens a client of it. Every client opened must share the state: for a lease kept in memory, the same lease; for one kept in files or a database, a new client over the same files or tables, as another process would open. Each call of Factory must start from empty state.