credtest

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package credtest provides test-only credential backends so downstream tests can exercise keychain-mode behaviour without pulling in github.com/zalando/go-keyring. Useful for:

  • Tests of resolvers (pkg/chat, pkg/vcs) and setup wizards (pkg/setup/ai) that want deterministic behaviour for Store / Retrieve / Delete without touching the host keychain.
  • Downstream tools that unit-test their own credential flows.

MemoryBackend stores everything in an in-process map guarded by a mutex — nothing ever reaches a session bus or platform API, so this package is safe to link into a binary that must prove (via SBOM or similar audit) that it performs no IPC to the keychain infrastructure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryBackend

type MemoryBackend struct {
	// contains filtered or unexported fields
}

MemoryBackend is a concurrency-safe in-memory implementation of credentials.Backend. The zero value is usable; Store on an uninitialised MemoryBackend works correctly.

func Install

func Install(t testingT) *MemoryBackend

Install registers a fresh MemoryBackend as the process-wide credentials backend for the duration of the test, restoring a stub backend via t.Cleanup. Call this at the top of any test that wants to exercise real Store / Retrieve / Delete without actually touching the OS keychain.

Returns the backend so tests can pre-populate entries directly if they want to seed data without going through credentials.Store.

func (*MemoryBackend) Available

func (*MemoryBackend) Available() bool

Available reports true so credentials.KeychainAvailable returns true and setup wizards offer the keychain option under this backend. Tests that want the "unavailable" path should not register this backend — the default stub already reports false.

func (*MemoryBackend) Delete

func (m *MemoryBackend) Delete(ctx context.Context, service, account string) error

Delete removes a secret. Idempotent: deleting a non-existent entry returns nil, matching the real Backend.

func (*MemoryBackend) Retrieve

func (m *MemoryBackend) Retrieve(ctx context.Context, service, account string) (string, error)

Retrieve reads a previously-stored secret. Returns credentials.ErrCredentialNotFound when the pair has never been written — matching the real Backend's contract so resolvers behave identically against either implementation.

func (*MemoryBackend) Store

func (m *MemoryBackend) Store(ctx context.Context, service, account, secret string) error

Store writes a secret. Overwrites existing entries for the same service/account pair, matching the real keychain Backend. The context is honoured — a cancelled context aborts the write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL