# secret/secrettest

> Package secrettest is the conformance kit for secret.Vault implementations, and an in-memory Vault with fault hooks for tests of code that keeps credentials.

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

```go
import "github.com/barevoidco/zelk/core/secret/secrettest"
```

Package secrettest is the conformance kit for [secret.Vault](/reference/go/secret/#vault) implementations, and an in-memory Vault with fault hooks for tests of code that keeps credentials. zelk's keychain vaults run the kit, and so should any vault a host writes (docs/design/keychain.md).


## Run

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

Run checks that the vaults f makes behave as [secret.Vault](/reference/go/secret/#vault) requires.


## Factory

```go
type Factory func(t *testing.T) secret.Vault
```

Factory returns a vault for one case, empty of the items the case will make. A vault backed by a real keychain should make its ids unique and remove its items when t ends.


## Vault

```go
type Vault struct {
	// Name is the backend's name; "fake" when empty.
	Name   string
	Before func(op string, r secret.Ref) error
	After  func(op string, r secret.Ref) error
	// contains filtered or unexported fields
}
```

Vault is a vault kept in memory, for tests. Before and After, when set, run around each call's effect with the call's name ("create", "get", "delete") and ref: an error from Before stops the call before its effect, one from After is returned after it, as a call whose result was lost would be (ErrUncertain, say).


### Vault.Backend

```go
func (v *Vault) Backend() string
```

Backend returns the vault's name.


### Vault.Create

```go
func (v *Vault) Create(_ context.Context, r secret.Ref, _ string, data []byte) error
```

Create stores a new item.


### Vault.Delete

```go
func (v *Vault) Delete(_ context.Context, r secret.Ref) error
```

Delete removes an item.


### Vault.Get

```go
func (v *Vault) Get(_ context.Context, r secret.Ref) ([]byte, error)
```

Get returns the item's data.


### Vault.Items

```go
func (v *Vault) Items() map[string][]byte
```

Items returns a copy of what the vault holds, by id.


### Vault.NewRef

```go
func (v *Vault) NewRef(context.Context) (secret.Ref, error)
```

NewRef returns a ref with a random id.


### Vault.Put

```go
func (v *Vault) Put(id string, data []byte)
```

Put stores data under id directly, as another program might.
