Documentation
¶
Overview ¶
Package setectest implements a wrapper around setec types for testing.
Usage ¶
// Construct a database and add some secrets.
db := setecttest.NewDB(t, nil) // nil for default options
db.MustPut(db.Superuser, "name", "value")
// Construct a test server.
ss := setectest.NewServer(t, db, &setectest.ServerOptions{
WhoIs: setectest.AllAccess,
})
// Hook up the Server to the httptest package.
hs := httptest.NewServer(ss.Mux)
Index ¶
- func AllAccess(ctx context.Context, addr string) (*apitype.WhoIsResponse, error)
- type DB
- func (db *DB) MustActivate(caller db.Caller, name string, version api.SecretVersion)
- func (db *DB) MustCreateVersion(caller db.Caller, name string, version api.SecretVersion, value string)
- func (db *DB) MustGet(caller db.Caller, name string) *api.SecretValue
- func (db *DB) MustGetVersion(caller db.Caller, name string, version api.SecretVersion) *api.SecretValue
- func (db *DB) MustList(caller db.Caller) []*api.SecretInfo
- func (db *DB) MustPut(caller db.Caller, name, value string) api.SecretVersion
- type DBOptions
- type Server
- type ServerOptions
- type Ticker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
type DB struct {
Path string // the path of the database file
Key tink.AEAD // the key-encryption key (dummy)
Actual *db.DB // the underlying database
Superuser db.Caller // a pre-defined super-user for all secrets & operations
// contains filtered or unexported fields
}
DB is a wrapper around a setec database to simplify creating database instances for unit tests with the testing package.
func NewDB ¶
NewDB constructs a new empty DB that persists for the duration of the test and subtests governed by t. When t ends, the database is cleaned up. If opts == nil, default options are used (see DBOptions).
func (*DB) MustActivate ¶
MustActivate sets the active version of the named secret or fails.
func (*DB) MustCreateVersion ¶
func (db *DB) MustCreateVersion(caller db.Caller, name string, version api.SecretVersion, value string)
MustCreateVersion creates the specified version of the named secret or fails.
func (*DB) MustGetVersion ¶
func (db *DB) MustGetVersion(caller db.Caller, name string, version api.SecretVersion) *api.SecretValue
MustGetVersion returns the specified version of the named secret or fails.
type DBOptions ¶
type DBOptions struct {
// AuditLog is where audit logs are written; if nil, audit logs are
// discarded without error.
AuditLog *audit.Writer
}
DBOptions are options for constructing a test database. A nil *Options is ready for use and provides defaults as described.
type Server ¶
type Server struct {
Actual *server.Server // the underlying server
Mux *http.ServeMux // the serving mux populated by the server
}
Server is a wrapper to support running a standalone setec Server for unit tests with the testing package.
func NewServer ¶
func NewServer(t *testing.T, db *DB, opts *ServerOptions) *Server
NewServer constructs a new Server that reads data from db and persists for the duration of the test and subtests governed by t. When t ends, the server and its database are cleaned up. If opts == nil, default options are used (see ServerOptions).
type ServerOptions ¶
type ServerOptions struct {
// WhoIs is a function implementing the corresponding method of a local
// client. If nil, setectest.AllAccess is used by default.
WhoIs func(context.Context, string) (*apitype.WhoIsResponse, error)
// AuditLog is where audit logs are written; if nil, audit logs are
// discarded without error.
AuditLog *audit.Writer
}
ServerOptions are options for constructing a test server. A nil *ServerOptions is ready for use and provides defaults as described.
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker implements the [setec.Ticker] interface allowing a test to control the advancement of time to exercise polling.
func NewFakeTicker ¶
func NewFakeTicker() *Ticker
NewFakeTicker constructs a test-controled instance of the [setec.Ticker] interface that can be used by tests to control the advancement of updates to a [setec.Store].