# 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").

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/lease/leasetest (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
import "github.com/barevoidco/zelk/core/lease/leasetest"
```

Package leasetest is the conformance kit for [lease.Lease](/reference/go/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.


## Constants

```go
const TTL = 10 * time.Second
```

TTL is the grant length the kit asks for.


## Run

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

Run checks that the leases made by f behave as [lease.Lease](/reference/go/lease/#lease) and the rules in docs/design/durability.md ("Leases and stores") require.


## Factory

```go
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.
