testutils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutils is a generated GoMock package.

Index

Constants

View Source
const FlagKeyNotStringResult = MissingFlagKeyResult
View Source
const MissingFlagKeyResult = `{"test-flag":{"variations":{"true_var":true,"false_var":false},"targeting":[{"query` +
	`":"key eq \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false_var"}` +
	`,"trackEvents":false}}`
View Source
const MongoFindResultFlagNoStr = `[{"flag":123456,"variations":{"true_var":true,"false_var":false},"targeting":[{` +
	`"query":"key eq \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false` +
	`_var"},"trackEvents":false},{"flag":"test-flag","variations":{"true_var":true,"false_var":false},"targeting":[{` +
	`"query":"key eq \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false` +
	`_var"},"trackEvents":false}]`
View Source
const MongoFindResultString = `[{"flag":"test-flag","variations":{"true_var":true,"false_var":false},"targeting":` +
	`[{"query":"key eq \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"fal` +
	`se_var"},"trackEvents":false},{"flag":"test-flag2","variations":{"true_var":true,"false_var":false},"targeting"` +
	`:[{"query":"key eq \"not-a-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"fal` +
	`se_var"},"trackEvents":false}]`
View Source
const MongoMissingFlagKey = `[{"flag":"test-flag","variations":{"true_var":true,"false_var":false},"targeting":[{` +
	`"query":"key eq \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false` +
	`_var"},"trackEvents":false},{"variations":{"true_var":true,"false_var":false},"targeting":[{"query":"key eq \"n` +
	`ot-a-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false_var"},"trackEvents"` +
	`:false}]`
View Source
const QueryResult = `{"test-flag":{"variations":{"true_var":true,"false_var":false},"targeting":[{"query":"key eq` +
	` \"random-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false_var"},"trackEv` +
	`ents":false},"test-flag2":{"variations":{"true_var":true,"false_var":false},"targeting":[{"query":"key eq \"not` +
	`-a-key\"","percentage":{"true_var":0,"false_var":100}}],"defaultRule":{"variation":"false_var"},"trackEvents":false}}`
View Source
const RFC3339Regex = "" //nolint:lll // long literal that can not be wrapped

/* 161-byte string literal not displayed */

Variables

This section is empty.

Functions

func CopyContentToExistingTempFile

func CopyContentToExistingTempFile(t *testing.T, content string, file *os.File) *os.File

func CopyContentToNewTempFile

func CopyContentToNewTempFile(t *testing.T, content string) *os.File

func CopyFileToExistingTempFile

func CopyFileToExistingTempFile(t *testing.T, src string, file *os.File) *os.File

func CopyFileToNewTempFile

func CopyFileToNewTempFile(t *testing.T, src string) *os.File

func EncodedMd5Hash

func EncodedMd5Hash(content []byte) string

func ListenLocal

func ListenLocal(t *testing.T) (net.Listener, int)

ListenLocal binds a TCP listener on a free loopback port and returns it with the port. The listener stays bound until the test ends, so no other test can take the port: hand it to the component under test (for example api.WithListener) instead of closing it and binding the port again later. The component that serves on it closes it; the test cleanup closing it a second time is harmless.

func ReplaceAndCopyFileToExistingFile

func ReplaceAndCopyFileToExistingFile(t *testing.T, src string, dstFile *os.File, old, newStr string) *os.File

func ReplaceInFile

func ReplaceInFile(t *testing.T, file *os.File, old, newStr string)

Types

type ExportableMockEvent

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

func NewExportableMockEvent

func NewExportableMockEvent(name string) ExportableMockEvent

func (ExportableMockEvent) FormatInCSV

func (e ExportableMockEvent) FormatInCSV(_ *template.Template) ([]byte, error)

func (ExportableMockEvent) FormatInJSON

func (e ExportableMockEvent) FormatInJSON() ([]byte, error)

func (ExportableMockEvent) GetCreationDate

func (e ExportableMockEvent) GetCreationDate() int64

func (ExportableMockEvent) GetKey

func (e ExportableMockEvent) GetKey() string

func (ExportableMockEvent) GetUserKey

func (e ExportableMockEvent) GetUserKey() string

type GCStorageReaderMock

type GCStorageReaderMock struct {
	FileToRead string

	ShouldFail bool
	// contains filtered or unexported fields
}

func (*GCStorageReaderMock) Close

func (r *GCStorageReaderMock) Close() error

func (*GCStorageReaderMock) Read

func (r *GCStorageReaderMock) Read(p []byte) (int, error)

type HTTPClientMock

type HTTPClientMock struct {
	Headers    map[string][]string
	Body       string
	Signature  string
	StatusCode int
	ForceError bool
}

func (*HTTPClientMock) Do

func (h *HTTPClientMock) Do(req *http.Request) (*http.Response, error)

type MockedStorage

type MockedStorage struct {
	Server *fakestorage.Server
}

func NewMockedGCS

func NewMockedGCS(t *testing.T) MockedStorage

func (MockedStorage) WithFiles

func (m MockedStorage) WithFiles(t *testing.T, bucketName string, files map[string]string)

type Mockobject

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

Mockobject is a mock of object interface.

func NewMockobject

func NewMockobject(ctrl *gomock.Controller) *Mockobject

NewMockobject creates a new mock instance.

func (*Mockobject) Attrs

func (m *Mockobject) Attrs(ctx context.Context) (*storage.ObjectAttrs, error)

Attrs mocks base method.

func (*Mockobject) EXPECT

func (m *Mockobject) EXPECT() *MockobjectMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*Mockobject) NewReader

func (m *Mockobject) NewReader(ctx context.Context) (*storage.Reader, error)

NewReader mocks base method.

type MockobjectMockRecorder

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

MockobjectMockRecorder is the mock recorder for Mockobject.

func (*MockobjectMockRecorder) Attrs

func (mr *MockobjectMockRecorder) Attrs(ctx any) *gomock.Call

Attrs indicates an expected call of Attrs.

func (*MockobjectMockRecorder) NewReader

func (mr *MockobjectMockRecorder) NewReader(ctx any) *gomock.Call

NewReader indicates an expected call of NewReader.

type S3ManagerV2Mock

type S3ManagerV2Mock struct {
	S3ManagerMockFileSystem map[string]string
	TestDataLocation        string
}

func (*S3ManagerV2Mock) DownloadObject

func (*S3ManagerV2Mock) UploadObject

type S3PrefixMock

type S3PrefixMock struct {
	// ListErr, if set, is returned by every ListObjectsV2 call.
	ListErr error
	// DownloadErr, if set, is returned by every DownloadObject call.
	DownloadErr error
	// BeforeDownload, if set, is called with the key at the start of every DownloadObject call,
	// without the mock lock held, so it can call Put and Delete to swap an object between the list
	// and the download.
	BeforeDownload func(key string)

	// PageSize is the max number of keys returned by one ListObjectsV2 call (default 1000).
	PageSize int

	// NoETag lists the objects with an empty ETag, like some S3 compatible stores do.
	NoETag bool
	// contains filtered or unexported fields
}

S3PrefixMock is an in-memory fake of a S3 bucket implementing both the lister and the downloader APIs used by the S3 retriever v2. It supports prefix/delimiter semantics, pagination, ETags and call counters.

func (*S3PrefixMock) Delete

func (m *S3PrefixMock) Delete(key string)

Delete removes an object.

func (*S3PrefixMock) DownloadCalls

func (m *S3PrefixMock) DownloadCalls(key string) int

DownloadCalls returns the number of times the key was downloaded.

func (*S3PrefixMock) DownloadObject

DownloadObject writes the content of the object in the WriterAt of the input.

func (*S3PrefixMock) ListCalls

func (m *S3PrefixMock) ListCalls() int

ListCalls returns the number of ListObjectsV2 calls.

func (*S3PrefixMock) ListObjectsV2

func (m *S3PrefixMock) ListObjectsV2(
	_ context.Context,
	params *s3.ListObjectsV2Input,
	_ ...func(*s3.Options),
) (*s3.ListObjectsV2Output, error)

ListObjectsV2 mimics the S3 API (prefix, delimiter, continuation token, max keys).

func (*S3PrefixMock) Put

func (m *S3PrefixMock) Put(key, content string)

Put creates or replaces an object. The ETag is derived from the content.

func (*S3PrefixMock) SetDownloadErrKey

func (m *S3PrefixMock) SetDownloadErrKey(key string, err error)

SetDownloadErrKey makes the download of one key fail with err, nil removes the failure.

func (*S3PrefixMock) TotalDownloadCalls

func (m *S3PrefixMock) TotalDownloadCalls() int

TotalDownloadCalls returns the number of downloads, all keys included.

Directories

Path Synopsis
Package gopherstack starts the gopherstack AWS emulator (https://github.com/blackbirdworks/gopherstack) in a Docker container, to run end-to-end tests of the AWS-backed components (S3, Kinesis, SQS).
Package gopherstack starts the gopherstack AWS emulator (https://github.com/blackbirdworks/gopherstack) in a Docker container, to run end-to-end tests of the AWS-backed components (S3, Kinesis, SQS).
mockretriever
Package mockretriever provides mock implementations of various retriever interfaces for testing purposes in the semaphore project.
Package mockretriever provides mock implementations of various retriever interfaces for testing purposes in the semaphore project.

Jump to

Keyboard shortcuts

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