teststorage

package
v0.310.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 22 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequireEqual added in v0.310.0

func RequireEqual(t testing.TB, expected, got []Sample, msgAndArgs ...any)

RequireEqual is a special require equal that correctly compare Prometheus structures.

In comparison to testutil.RequireEqual, this function adds special logic for comparing []Samples.

It also ignores ordering between consecutive stale samples to avoid false negatives due to map iteration order in staleness tracking.

func RequireNotEqual added in v0.310.0

func RequireNotEqual(t testing.TB, expected, got []Sample, msgAndArgs ...any)

RequireNotEqual is the negation of RequireEqual.

Types

type Appendable added in v0.310.0

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

Appendable is a storage.Appendable mock. It allows recording all samples that were added through the appender and injecting errors. Appendable will panic if more than one Appender is open.

func NewAppendable added in v0.310.0

func NewAppendable() *Appendable

NewAppendable returns mock Appendable.

func (*Appendable) Appender added in v0.310.0

func (a *Appendable) Appender(ctx context.Context) storage.Appender

func (*Appendable) AppenderV2 added in v0.310.0

func (a *Appendable) AppenderV2(ctx context.Context) storage.AppenderV2

func (*Appendable) PendingSamples added in v0.310.0

func (a *Appendable) PendingSamples() []Sample

PendingSamples returns pending samples (samples appended without commit).

func (*Appendable) ResultMetadata added in v0.310.0

func (a *Appendable) ResultMetadata() []Sample

ResultMetadata returns resultSamples with samples only containing L and M. This is for compatibility with tests that only focus on metadata.

TODO: Rewrite tests to test metadata on resultSamples instead.

func (*Appendable) ResultReset added in v0.310.0

func (a *Appendable) ResultReset()

func (*Appendable) ResultSamples added in v0.310.0

func (a *Appendable) ResultSamples() []Sample

ResultSamples returns committed samples.

func (*Appendable) RolledbackSamples added in v0.310.0

func (a *Appendable) RolledbackSamples() []Sample

RolledbackSamples returns rolled back samples.

func (*Appendable) SkipRecording added in v0.310.0

func (a *Appendable) SkipRecording(skipRecording bool) *Appendable

SkipRecording enables or disables recording appended samples. If skipped, Appendable allocs less, but Result*() methods will give always empty results. This is useful for benchmarking.

func (*Appendable) String added in v0.310.0

func (a *Appendable) String() string

func (*Appendable) Then added in v0.310.0

func (a *Appendable) Then(appendable compatAppendable) *Appendable

Then chains another appender from the provided Appendable for the Appender calls.

func (*Appendable) WithErrs added in v0.310.0

func (a *Appendable) WithErrs(appendErrFn func(ls labels.Labels) error, appendExemplarsError, commitErr error) *Appendable

WithErrs allows injecting errors to the appender.

type Option added in v0.310.0

type Option func(opt *tsdb.Options)

type Sample added in v0.310.0

Sample represents test, combined sample for mocking storage.AppenderV2.

func (Sample) Equals added in v0.310.0

func (s Sample) Equals(other Sample) bool

func (Sample) IsStale added in v0.310.0

func (s Sample) IsStale() bool

IsStale returns whether the sample represents a stale sample, according to https://prometheus.io/docs/specs/native_histograms/#staleness-markers.

func (Sample) String added in v0.310.0

func (s Sample) String() string

type TestStorage

type TestStorage struct {
	*tsdb.DB
	// contains filtered or unexported fields
}

func New

func New(t testing.TB, o ...Option) *TestStorage

New returns a new TestStorage for testing purposes that removes all associated files on closing.

Caller does not need to close the TestStorage after use, it's deferred via t.Cleanup.

func NewWithError added in v0.52.0

func NewWithError(o ...Option) (*TestStorage, error)

NewWithError returns a new TestStorage for user facing tests, which reports errors directly.

It's a caller responsibility to close the TestStorage after use.

func (TestStorage) Close

func (s TestStorage) Close() error

Jump to

Keyboard shortcuts

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