internal

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicatePath = errors.New("duplicate path")
	ErrPathNotFound  = errors.New("path not found")
)

Functions

func CollectAndRegexpCompare

func CollectAndRegexpCompare(colltor prometheus.Collector, expectRdr io.Reader, metricNames ...string) error

CollectAndRegexpCompare is similar to testutil.CollectAndCompare() but the expected lines are regexp patterns. Note that unlike testutil.CollectAndCompare(), the metricName MUST be specified to get any collected result.

func RedactUrl added in v1.5.0

func RedactUrl(dsnUrl string) string

RedactUrl redacts the user/pass components of the url

func SimpleRegexpLineDiff

func SimpleRegexpLineDiff(regexpLines []string, gotLines []string) string

SimpleRegexpLineDiff performs a simple/dumb line-by-line diff between two arrays of lines. The expected array of lines are regexp patterns. Returns line(s) which diff. Empty string is returned if there are no diffs.

func UnrootedPath

func UnrootedPath(pathStr string) string

Types

type NonRandomReader added in v1.5.0

type NonRandomReader struct {
	sync.Mutex
	// contains filtered or unexported fields
}

NonRandomReader is a reader that returns a deterministic (non-random) sequence of bytes. Intended for testing to supply deterministic "random" values. The sequence of bytes eventually rolls over and repeats itself, so this reader should NOT be used in production code.

func NewNonRandomReader added in v1.5.0

func NewNonRandomReader(startVal byte) *NonRandomReader

NewNonRandomReader returns a new NonRandomReader. The first byte supplied will be `startVal`.

func (*NonRandomReader) Read added in v1.5.0

func (nrr *NonRandomReader) Read(buf []byte) (count int, err error)

Read is thread-safe and implements io.Reader interface. Fills buffer with non-random bytes and returns count of filled bytes, which in this case is always the length of the buffer.

Returns byte values in the following deterministic sequence (note that all byte values are modulo 256): 1st set of 256 bytes: [(start)..(start+255)] 2nd set of 256 bytes: [(start+1)..(start+1+255)] 3rd set of 256 bytes: [(start+2)..(start+2+255)] ... 255th set of 256 bytes: [(start+254)..(start+254+255)] 256th set of 256 bytes: [(start+255)..(start+255+255)] 257th set of 256 bytes: [(start)..(start+255)] (rolled over, sequence repeats itself)

Reason for doing this is that uuid consumes 16 bytes on each uuid generation. If we don't shift the sequence after every 256 bytes, than NonRandomReader will only supply enough bytes for 16 unique uuids. If we shift the sequence after every 256 bytes, than NonRandomReader will supply enough bytes for 256 unique uuids before rolling over.

type RandomSecretData added in v1.5.0

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

type RandomSecretSink added in v1.5.0

type RandomSecretSink struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RandomSecretSink binds a secret value with a random value. The count of secret/random pairs stored is limited. When full, any new secret/random pair added results in deleting the oldest pair. If a secret has already been added previously, a new secret/random pair is not created/added, but its last-used timestamp is updated.

func (*RandomSecretSink) Add added in v1.5.0

func (rss *RandomSecretSink) Add(actualSecret string) (randomSecret string, err error)

Add is thread-safe and creates/binds a random value with the secret. If secret has already been previously added, then it returns the secret's previously-created random value. The secret/random pair's last-used timestamp is updated. If full, the oldest secret/random pair is deleted.

type SafeMapFS

type SafeMapFS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SafeMapFS is a thread-safe wrapper around fstest.MapFS

func NewSafeMapFS

func NewSafeMapFS() *SafeMapFS

func (*SafeMapFS) AddMapFile

func (mfs *SafeMapFS) AddMapFile(pathStr string, mapf *fstest.MapFile) error

func (*SafeMapFS) GetMapFile

func (mfs *SafeMapFS) GetMapFile(pathStr string) (*fstest.MapFile, error)

func (*SafeMapFS) Glob

func (mfs *SafeMapFS) Glob(pattern string) ([]string, error)

Glob implements io/fs.GlobFS interface

func (*SafeMapFS) Open

func (mfs *SafeMapFS) Open(name string) (fs.File, error)

Open implements io/fs.FS interface

func (*SafeMapFS) ReadDir

func (mfs *SafeMapFS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir implements io/fs.ReadDirFS interface

func (*SafeMapFS) ReadFile

func (mfs *SafeMapFS) ReadFile(name string) ([]byte, error)

ReadFile implements io/fs.ReadFileFS interface

func (*SafeMapFS) RemoveMapFile

func (mfs *SafeMapFS) RemoveMapFile(pathStr string) (*fstest.MapFile, error)

func (*SafeMapFS) Stat

func (mfs *SafeMapFS) Stat(name string) (fs.FileInfo, error)

Stat implements io/fs.StatFS interface

func (*SafeMapFS) Sub

func (mfs *SafeMapFS) Sub(dir string) (fs.FS, error)

Sub implements io/fs.SubFS interface

func (*SafeMapFS) UpsertMapFile

func (mfs *SafeMapFS) UpsertMapFile(pathStr string, mapf *fstest.MapFile) error

type SecretSink added in v1.5.0

type SecretSink interface {
	Add(actualSecret string) (randomSecret string, err error)
}

SecretSink returns a

func NewRandomSecretSink added in v1.5.0

func NewRandomSecretSink(maxCount int) SecretSink

NewRandomSecretSink returns a SecretSink that can hold `maxCount` secret/random pairs.