testhelper

package
v14.10.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RepositoryAuthToken is the default token used to authenticate
	// against other Gitaly servers. It is inject as part of the
	// GitalyServers metadata.
	RepositoryAuthToken = "the-secret-token"
	// DefaultStorageName is the default name of the Gitaly storage.
	DefaultStorageName = "default"
)

Variables

This section is empty.

Functions

func Context

func Context(t testing.TB, opts ...ContextOpt) context.Context

Context returns that gets canceled at the end of the test.

func ContextWithoutCancel added in v14.6.0

func ContextWithoutCancel(opts ...ContextOpt) context.Context

ContextWithoutCancel returns a non-cancellable context.

func CopyFile

func CopyFile(t testing.TB, src, dst string)

CopyFile copies a file at the path src to a file at the path dst

func CreateGlobalDirectory added in v14.5.0

func CreateGlobalDirectory(t testing.TB, name string) string

CreateGlobalDirectory creates a directory in the test directory that is shared across all between all tests.

func GenerateCerts

func GenerateCerts(t *testing.T) (string, string)

GenerateCerts creates a certificate that can be used to establish TLS protected TCP connection. It returns paths to the file with the certificate and its private key.

func GetLocalhostListener

func GetLocalhostListener(t testing.TB) (net.Listener, string)

GetLocalhostListener listens on the next available TCP port and returns the listener and the localhost address (host:port) string.

func GetTemporaryGitalySocketFileName

func GetTemporaryGitalySocketFileName(t testing.TB) string

GetTemporaryGitalySocketFileName will return a unique, useable socket file name

func GitLabTestCommit

func GitLabTestCommit(id string) *gitalypb.GitCommit

GitLabTestCommit provides a key value lookup for commits in the GitLab-Test repository

func GitlabTestStoragePath

func GitlabTestStoragePath() string

GitlabTestStoragePath returns the storage path to the gitlab-test repo.

func IsPraefectEnabled added in v14.8.0

func IsPraefectEnabled() bool

IsPraefectEnabled returns whether this testing run is done with Praefect in front of the Gitaly.

func MergeIncomingMetadata

func MergeIncomingMetadata(ctx context.Context, md ...metadata.MD) context.Context

MergeIncomingMetadata merges provided metadata-s and returns context with resulting value.

func MergeOutgoingMetadata

func MergeOutgoingMetadata(ctx context.Context, md ...metadata.MD) context.Context

MergeOutgoingMetadata merges provided metadata-s and returns context with resulting value.

func ModifyEnvironment

func ModifyEnvironment(t testing.TB, key string, value string)

ModifyEnvironment will change an environment variable and revert it when the test completed.

func MustClose

func MustClose(t testing.TB, closer io.Closer)

MustClose calls Close() on the Closer and fails the test in case it returns an error. This function is useful when closing via `defer`, as a simple `defer require.NoError(t, closer.Close())` would cause `closer.Close()` to be executed early already.

func MustReadFile

func MustReadFile(t testing.TB, filename string) []byte

MustReadFile returns the content of a file or fails at once.

func MustRunCommand

func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) []byte

MustRunCommand runs a command with an optional standard input and returns the standard output, or fails.

func NewDiscardingLogEntry added in v14.6.0

func NewDiscardingLogEntry(tb testing.TB) *logrus.Entry

NewDiscardingLogEntry creates a logrus entry that discards everything.

func NewDiscardingLogger added in v14.6.0

func NewDiscardingLogger(tb testing.TB) *logrus.Logger

NewDiscardingLogger creates a logger that discards everything.

func NewHealthServerWithListener

func NewHealthServerWithListener(t testing.TB, listener net.Listener) *health.Server

NewHealthServerWithListener creates a new gRPC server with the health server set up. It will listen on the given listener.

func NewServerWithHealth

func NewServerWithHealth(t testing.TB, socketName string) *health.Server

NewServerWithHealth creates a new gRPC server with the health server set up. It will listen on the socket identified by `socketName`.

func ProtoEqual added in v14.6.0

func ProtoEqual(t testing.TB, expected, actual interface{})

ProtoEqual asserts that expected and actual protobuf messages are equal. It can accept not only proto.Message, but slices, maps, and structs too. This is required as comparing messages directly with `require.Equal` doesn't work.

func RequireGrpcCode added in v14.6.0

func RequireGrpcCode(t testing.TB, err error, expectedCode codes.Code)

RequireGrpcCode asserts that the error has the expected gRPC status code.

func RequireGrpcError

func RequireGrpcError(t testing.TB, expected, actual error)

RequireGrpcError asserts that expected and actual gRPC errors are equal. Comparing gRPC errors directly with `require.Equal()` will not typically work correct.

func Run added in v14.4.0

func Run(m *testing.M, opts ...RunOption)

Run sets up required testing state and executes the given test suite. It can optionally receive a variable number of RunOptions.

func SetCtxGrpcMethod

func SetCtxGrpcMethod(ctx context.Context, method string) context.Context

SetCtxGrpcMethod will set the gRPC context value for the proper key responsible for an RPC full method name. This directly corresponds to the gRPC function responsible for extracting the method: https://godoc.org/google.golang.org/grpc#Method

func SkipWithPraefect added in v14.4.0

func SkipWithPraefect(t testing.TB, reason string)

SkipWithPraefect skips the test if it is being executed with Praefect in front of the Gitaly.

func TempDir

func TempDir(t testing.TB) string

TempDir is a wrapper around os.MkdirTemp that provides a cleanup function.

func WriteExecutable

func WriteExecutable(t testing.TB, path string, content []byte) string

WriteExecutable ensures that the parent directory exists, and writes an executable with provided content. The executable must not exist previous to writing it. Returns the path of the written executable.

Types

type Cleanup

type Cleanup func()

Cleanup functions should be called in a defer statement immediately after they are returned from a test helper

type ContextOpt

type ContextOpt func(context.Context) context.Context

ContextOpt returns a new context instance with the new additions to it.

func ContextWithLogger

func ContextWithLogger(logger *log.Entry) ContextOpt

ContextWithLogger allows to inject provided logger into the context.

type FeatureSet

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

FeatureSet is a representation of a set of features that should be disabled. This is useful in situations where a test needs to test any combination of features toggled on and off. It is designed to disable features as all features are enabled by default, please see: testhelper.Context()

func (FeatureSet) Apply added in v14.6.0

func (f FeatureSet) Apply(ctx context.Context) context.Context

Apply applies all feature flags in the given FeatureSet to the given context.

func (FeatureSet) Desc

func (f FeatureSet) Desc() string

Desc describes the feature such that it is suitable as a testcase description.

type FeatureSets

type FeatureSets []FeatureSet

FeatureSets is a slice containing many FeatureSets

func NewFeatureSets

func NewFeatureSets(features ...featureflag.FeatureFlag) FeatureSets

NewFeatureSets takes Go feature flags and returns the combination of FeatureSets.

func NewFeatureSetsWithRubyFlags added in v14.6.0

func NewFeatureSetsWithRubyFlags(goFeatures []featureflag.FeatureFlag, rubyFeatures []featureflag.FeatureFlag) FeatureSets

NewFeatureSetsWithRubyFlags takes a Go- and Ruby-specific feature flags and returns a the combination of FeatureSets.

func (FeatureSets) Bench added in v14.5.0

func (s FeatureSets) Bench(b *testing.B, test func(b *testing.B, ctx context.Context))

Bench executes the given benchmarking function for each of the FeatureSets. The passed in context has the feature flags set accordingly.

func (FeatureSets) Run

func (s FeatureSets) Run(t *testing.T, test func(t *testing.T, ctx context.Context))

Run executes the given test function for each of the FeatureSets. The passed in context has the feature flags set accordingly.

type RunOption added in v14.4.0

type RunOption func(*runConfig)

RunOption is an option that can be passed to Run.

func WithDisabledGoroutineChecker deprecated added in v14.4.0

func WithDisabledGoroutineChecker() RunOption

WithDisabledGoroutineChecker disables checking for leaked Goroutines after tests have run. This should ideally only be used as a temporary measure until all Goroutine leaks have been fixed.

Deprecated: This should not be used, but instead you should try to fix all Goroutine leakages.

func WithSetup added in v14.4.0

func WithSetup(setup func() error) RunOption

WithSetup allows the caller of Run to pass a setup function that will be called after global test state has been configured.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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