secret/secrettest
import "github.com/barevoidco/zelk/core/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. zelk’s keychain vaults run the kit, and so should any vault a host writes (docs/design/keychain.md).
func Run(t *testing.T, f Factory)Run checks that the vaults f makes behave as secret.Vault requires.
Factory
Section titled “Factory”type Factory func(t *testing.T) secret.VaultFactory 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.
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
Section titled “Vault.Backend”func (v *Vault) Backend() stringBackend returns the vault’s name.
Vault.Create
Section titled “Vault.Create”func (v *Vault) Create(_ context.Context, r secret.Ref, _ string, data []byte) errorCreate stores a new item.
Vault.Delete
Section titled “Vault.Delete”func (v *Vault) Delete(_ context.Context, r secret.Ref) errorDelete removes an item.
Vault.Get
Section titled “Vault.Get”func (v *Vault) Get(_ context.Context, r secret.Ref) ([]byte, error)Get returns the item’s data.
Vault.Items
Section titled “Vault.Items”func (v *Vault) Items() map[string][]byteItems returns a copy of what the vault holds, by id.
Vault.NewRef
Section titled “Vault.NewRef”func (v *Vault) NewRef(context.Context) (secret.Ref, error)NewRef returns a ref with a random id.
Vault.Put
Section titled “Vault.Put”func (v *Vault) Put(id string, data []byte)Put stores data under id directly, as another program might.