Documentation ¶
Index ¶
- func GenerateTestSession(params SessionParams) []apievents.AuditEvent
- func NewFakeStreamer(events []apievents.AuditEvent, interval time.Duration) events.SessionStreamer
- func NewSlowEmitter(delay time.Duration) events.Emitter
- func PrepareEvent(event apievents.AuditEvent) apievents.PreparedSessionEvent
- type ChannelEmitter
- type ChannelRecorder
- func (e *ChannelRecorder) C() <-chan apievents.AuditEvent
- func (e *ChannelRecorder) Close(ctx context.Context) error
- func (e *ChannelRecorder) Complete(ctx context.Context) error
- func (e *ChannelRecorder) CreateAuditStream(ctx context.Context, sid session.ID) (apievents.Stream, error)
- func (e *ChannelRecorder) Done() <-chan struct{}
- func (e *ChannelRecorder) RecordEvent(ctx context.Context, event apievents.PreparedSessionEvent) error
- func (e *ChannelRecorder) ResumeAuditStream(ctx context.Context, sid session.ID, uploadID string) (apievents.Stream, error)
- func (e *ChannelRecorder) Status() <-chan apievents.StreamStatus
- func (*ChannelRecorder) Write(b []byte) (int, error)
- type CounterEmitter
- type MemoryUpload
- type MemoryUploader
- func (m *MemoryUploader) CompleteUpload(ctx context.Context, upload events.StreamUpload, parts []events.StreamPart) error
- func (m *MemoryUploader) CreateUpload(ctx context.Context, sessionID session.ID) (*events.StreamUpload, error)
- func (m *MemoryUploader) Download(ctx context.Context, sessionID session.ID, writer io.WriterAt) error
- func (m *MemoryUploader) GetParts(uploadID string) ([][]byte, error)
- func (m *MemoryUploader) GetUploadMetadata(sid session.ID) events.UploadMetadata
- func (m *MemoryUploader) IsCompleted(uploadID string) bool
- func (m *MemoryUploader) ListParts(ctx context.Context, upload events.StreamUpload) ([]events.StreamPart, error)
- func (m *MemoryUploader) ListUploads(ctx context.Context) ([]events.StreamUpload, error)
- func (m *MemoryUploader) ReserveUploadPart(ctx context.Context, upload events.StreamUpload, partNumber int64) error
- func (m *MemoryUploader) Reset()
- func (m *MemoryUploader) Upload(ctx context.Context, sessionID session.ID, readCloser io.Reader) (string, error)
- func (m *MemoryUploader) UploadPart(ctx context.Context, upload events.StreamUpload, partNumber int64, ...) (*events.StreamPart, error)
- type MockAuditLog
- type MockRecorderEmitter
- func (e *MockRecorderEmitter) Close(ctx context.Context) error
- func (e *MockRecorderEmitter) Complete(ctx context.Context) error
- func (e *MockRecorderEmitter) CreateAuditStream(ctx context.Context, sid session.ID) (apievents.Stream, error)
- func (e *MockRecorderEmitter) Done() <-chan struct{}
- func (e *MockRecorderEmitter) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error
- func (e *MockRecorderEmitter) Events() []apievents.AuditEvent
- func (e *MockRecorderEmitter) LastEvent() apievents.AuditEvent
- func (e *MockRecorderEmitter) RecordEvent(ctx context.Context, event apievents.PreparedSessionEvent) error
- func (e *MockRecorderEmitter) Reset()
- func (e *MockRecorderEmitter) ResumeAuditStream(ctx context.Context, sid session.ID, uploadID string) (apievents.Stream, error)
- func (e *MockRecorderEmitter) Status() <-chan apievents.StreamStatus
- func (e *MockRecorderEmitter) Write(_ []byte) (int, error)
- type MockUploader
- func (m *MockUploader) CompleteUpload(ctx context.Context, upload events.StreamUpload, parts []events.StreamPart) error
- func (m *MockUploader) CreateUpload(ctx context.Context, sessionID session.ID) (*events.StreamUpload, error)
- func (m *MockUploader) ListParts(_ context.Context, _ events.StreamUpload) ([]events.StreamPart, error)
- func (m *MockUploader) ListUploads(ctx context.Context) ([]events.StreamUpload, error)
- func (m *MockUploader) ReserveUploadPart(_ context.Context, _ events.StreamUpload, _ int64) error
- type SessionParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateTestSession ¶
func GenerateTestSession(params SessionParams) []apievents.AuditEvent
GenerateTestSession generates test session events starting with session start event, adds printEvents events and returns the result.
func NewFakeStreamer ¶
func NewFakeStreamer(events []apievents.AuditEvent, interval time.Duration) events.SessionStreamer
NewFakeStreamer returns a session streamer that streams the provided events, sending one event per interval. An interval of 0 sends the events immediately, throttled only by the ability of the receiver to keep up.
func NewSlowEmitter ¶
NewSlowEmitter creates an emitter that introduces an artificial delay before "emitting" (discarding) an audit event.
func PrepareEvent ¶
func PrepareEvent(event apievents.AuditEvent) apievents.PreparedSessionEvent
Types ¶
type ChannelEmitter ¶
type ChannelEmitter struct {
// contains filtered or unexported fields
}
ChannelEmitter emits audit events by writing them to a channel.
func NewChannelEmitter ¶
func NewChannelEmitter(capacity int) *ChannelEmitter
NewChannelEmitter returns a new instance of test emitter.
func (*ChannelEmitter) C ¶
func (e *ChannelEmitter) C() <-chan apievents.AuditEvent
func (*ChannelEmitter) EmitAuditEvent ¶
func (e *ChannelEmitter) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error
type ChannelRecorder ¶
type ChannelRecorder struct {
// contains filtered or unexported fields
}
ChannelRecorder records session events by writing them to a channel.
func NewChannelRecorder ¶
func NewChannelRecorder(capacity int) *ChannelRecorder
NewChannelRecorder returns a new instance of test recorder.
func (*ChannelRecorder) C ¶
func (e *ChannelRecorder) C() <-chan apievents.AuditEvent
func (*ChannelRecorder) CreateAuditStream ¶
func (*ChannelRecorder) Done ¶
func (e *ChannelRecorder) Done() <-chan struct{}
func (*ChannelRecorder) RecordEvent ¶
func (e *ChannelRecorder) RecordEvent(ctx context.Context, event apievents.PreparedSessionEvent) error
func (*ChannelRecorder) ResumeAuditStream ¶
func (*ChannelRecorder) Status ¶
func (e *ChannelRecorder) Status() <-chan apievents.StreamStatus
type CounterEmitter ¶
type CounterEmitter struct {
// contains filtered or unexported fields
}
func NewCountingEmitter ¶
func NewCountingEmitter() *CounterEmitter
NewCountingEmitter returns an emitter that counts the number of events that are emitted. It is safe for concurrent use.
func (*CounterEmitter) Count ¶
func (c *CounterEmitter) Count() int64
Count returns the number of events that have been emitted. It is safe for concurrent use.
func (*CounterEmitter) EmitAuditEvent ¶
func (c *CounterEmitter) EmitAuditEvent(ctx context.Context, event events.AuditEvent) error
type MemoryUpload ¶
type MemoryUpload struct { // Initiated contains the timestamp of when the upload // was initiated, not always initialized Initiated time.Time // contains filtered or unexported fields }
MemoryUpload is used in tests
type MemoryUploader ¶
MemoryUploader uploads all bytes to memory, used in tests
func NewMemoryUploader ¶
func NewMemoryUploader(eventsC ...chan events.UploadEvent) *MemoryUploader
NewMemoryUploader returns a new memory uploader implementing multipart upload
func (*MemoryUploader) CompleteUpload ¶
func (m *MemoryUploader) CompleteUpload(ctx context.Context, upload events.StreamUpload, parts []events.StreamPart) error
CompleteUpload completes the upload
func (*MemoryUploader) CreateUpload ¶
func (m *MemoryUploader) CreateUpload(ctx context.Context, sessionID session.ID) (*events.StreamUpload, error)
CreateUpload creates a multipart upload
func (*MemoryUploader) Download ¶
func (m *MemoryUploader) Download(ctx context.Context, sessionID session.ID, writer io.WriterAt) error
Download downloads session tarball and writes it to writer
func (*MemoryUploader) GetParts ¶
func (m *MemoryUploader) GetParts(uploadID string) ([][]byte, error)
GetParts returns upload parts uploaded up to date, sorted by part number
func (*MemoryUploader) GetUploadMetadata ¶
func (m *MemoryUploader) GetUploadMetadata(sid session.ID) events.UploadMetadata
GetUploadMetadata gets the session upload metadata
func (*MemoryUploader) IsCompleted ¶
func (m *MemoryUploader) IsCompleted(uploadID string) bool
func (*MemoryUploader) ListParts ¶
func (m *MemoryUploader) ListParts(ctx context.Context, upload events.StreamUpload) ([]events.StreamPart, error)
ListParts returns all uploaded parts for the completed upload in sorted order
func (*MemoryUploader) ListUploads ¶
func (m *MemoryUploader) ListUploads(ctx context.Context) ([]events.StreamUpload, error)
ListUploads lists uploads that have been initiated but not completed with earlier uploads returned first.
func (*MemoryUploader) ReserveUploadPart ¶
func (m *MemoryUploader) ReserveUploadPart(ctx context.Context, upload events.StreamUpload, partNumber int64) error
ReserveUploadPart reserves an upload part.
func (*MemoryUploader) Reset ¶
func (m *MemoryUploader) Reset()
Reset resets all state, removes all uploads and objects
func (*MemoryUploader) Upload ¶
func (m *MemoryUploader) Upload(ctx context.Context, sessionID session.ID, readCloser io.Reader) (string, error)
Upload uploads session tarball and returns URL with uploaded file in case of success.
func (*MemoryUploader) UploadPart ¶
func (m *MemoryUploader) UploadPart(ctx context.Context, upload events.StreamUpload, partNumber int64, partBody io.ReadSeeker) (*events.StreamPart, error)
UploadPart uploads part and returns the part
type MockAuditLog ¶
type MockAuditLog struct { *events.DiscardAuditLog Emitter *MockRecorderEmitter SessionEvents []apievents.AuditEvent }
func (*MockAuditLog) EmitAuditEvent ¶
func (m *MockAuditLog) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error
func (*MockAuditLog) StreamSessionEvents ¶
func (m *MockAuditLog) StreamSessionEvents(ctx context.Context, sid session.ID, startIndex int64) (chan apievents.AuditEvent, chan error)
type MockRecorderEmitter ¶
type MockRecorderEmitter struct {
// contains filtered or unexported fields
}
MockRecorderEmitter is a recorder and emitter that stores all events.
func (*MockRecorderEmitter) Complete ¶
func (e *MockRecorderEmitter) Complete(ctx context.Context) error
func (*MockRecorderEmitter) CreateAuditStream ¶
func (*MockRecorderEmitter) Done ¶
func (e *MockRecorderEmitter) Done() <-chan struct{}
func (*MockRecorderEmitter) EmitAuditEvent ¶
func (e *MockRecorderEmitter) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error
EmitAuditEvent emits audit event
func (*MockRecorderEmitter) Events ¶
func (e *MockRecorderEmitter) Events() []apievents.AuditEvent
Events returns all the emitted events.
func (*MockRecorderEmitter) LastEvent ¶
func (e *MockRecorderEmitter) LastEvent() apievents.AuditEvent
LastEvent returns the last emitted event.
func (*MockRecorderEmitter) RecordEvent ¶
func (e *MockRecorderEmitter) RecordEvent(ctx context.Context, event apievents.PreparedSessionEvent) error
RecordEvent records a session event
func (*MockRecorderEmitter) Reset ¶
func (e *MockRecorderEmitter) Reset()
Reset clears the emitted events.
func (*MockRecorderEmitter) ResumeAuditStream ¶
func (*MockRecorderEmitter) Status ¶
func (e *MockRecorderEmitter) Status() <-chan apievents.StreamStatus
type MockUploader ¶
type MockUploader struct { events.MultipartUploader CreateUploadError error ReserveUploadPartError error ListPartsError error MockListUploads func(ctx context.Context) ([]events.StreamUpload, error) MockCompleteUpload func(ctx context.Context, upload events.StreamUpload, parts []events.StreamPart) error }
MockUploader is a limited implementation of [events.MultipartUploader] that allows injecting errors for testing purposes. MemoryUploader is a more complete implementation and should be preferred for testing the happy path.
func (*MockUploader) CompleteUpload ¶
func (m *MockUploader) CompleteUpload(ctx context.Context, upload events.StreamUpload, parts []events.StreamPart) error
func (*MockUploader) CreateUpload ¶
func (m *MockUploader) CreateUpload(ctx context.Context, sessionID session.ID) (*events.StreamUpload, error)
func (*MockUploader) ListParts ¶
func (m *MockUploader) ListParts(_ context.Context, _ events.StreamUpload) ([]events.StreamPart, error)
func (*MockUploader) ListUploads ¶
func (m *MockUploader) ListUploads(ctx context.Context) ([]events.StreamUpload, error)
func (*MockUploader) ReserveUploadPart ¶
func (m *MockUploader) ReserveUploadPart(_ context.Context, _ events.StreamUpload, _ int64) error
type SessionParams ¶
type SessionParams struct { // PrintEvents sets up print events count PrintEvents int64 // Clock is an optional clock setting start // and offset time of the event Clock clockwork.Clock // ServerID is an optional server ID ServerID string // SessionID is an optional session ID to set SessionID string // ClusterName is an optional originating cluster name ClusterName string }
SessionParams specifies optional parameters for generated session
func (*SessionParams) SetDefaults ¶
func (p *SessionParams) SetDefaults()
SetDefaults sets parameters defaults