testhelper

package
v14.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: MIT Imports: 46 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

View Source
var NewTestLogger = DiscardTestLogger

NewTestLogger creates logger that should be used in the tests.

Functions

func BuildGitalyGit2Go added in v14.2.0

func BuildGitalyGit2Go(t testing.TB, cfg config.Cfg)

BuildGitalyGit2Go builds the gitaly-git2go command and installs it into the binary directory.

func BuildGitalyHooks added in v14.2.0

func BuildGitalyHooks(t testing.TB, cfg config.Cfg)

BuildGitalyHooks builds the gitaly-hooks command and installs it into the binary directory.

func BuildGitalyLFSSmudge added in v14.2.0

func BuildGitalyLFSSmudge(t *testing.T, cfg config.Cfg)

BuildGitalyLFSSmudge builds the gitaly-lfs-smudge command and installs it into the binary directory.

func BuildGitalySSH added in v14.2.0

func BuildGitalySSH(t testing.TB, cfg config.Cfg)

BuildGitalySSH builds the gitaly-ssh command and installs it into the binary directory.

func Configure

func Configure() func()

Configure sets up the global test configuration. On failure, terminates the program.

func ConfigureGit

func ConfigureGit() error

ConfigureGit configures git for test purpose

func ConfigureRuby

func ConfigureRuby(cfg *config.Cfg) error

ConfigureRuby configures Ruby settings for test purposes at run time.

func Context

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

Context returns a 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 DiscardTestEntry

func DiscardTestEntry(tb testing.TB) *log.Entry

DiscardTestEntry creates a logrus entry that discards everything.

func DiscardTestLogger

func DiscardTestLogger(tb testing.TB) *log.Logger

DiscardTestLogger created a logrus hook that discards everything.

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 GitalyServersMetadataFromCfg

func GitalyServersMetadataFromCfg(t testing.TB, cfg config.Cfg) metadata.MD

GitalyServersMetadataFromCfg returns a metadata pair for gitaly-servers to be used in inter-gitaly operations.

func GitlabTestStoragePath

func GitlabTestStoragePath() string

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

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) func()

ModifyEnvironment will change an environment variable and return a func suitable for `defer` to change the value back.

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 MustHaveNoChildProcess

func MustHaveNoChildProcess()

MustHaveNoChildProcess panics if it finds a running or finished child process. It waits for 2 seconds for processes to be cleaned up by other goroutines.

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 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 ReceiveEOFWithTimeout

func ReceiveEOFWithTimeout(t testing.TB, errorFunc func() error)

ReceiveEOFWithTimeout reads to the end of the stream and will throw an error if a deadlock is suspected

func RequireGrpcError

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

RequireGrpcError asserts the passed err is of the same code as expectedCode.

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 SetHealthyNodes added in v14.1.0

func SetHealthyNodes(t testing.TB, ctx context.Context, db glsql.Querier, healthyNodes map[string]map[string][]string)

SetHealthyNodes sets the healthy nodes in the database as determined by the passed in map. The healthyNodes map is keyed by praefect name -> virtual storage -> storage. On each run, it clears all previous health checks from the table, so the passed in nodes are the only ones considered healthy after the function. As the healthy nodes are determined by the time of the last successful health check, this should be run in the same transastion as the tested query to prevent flakiness.

func TempDir

func TempDir(t testing.TB) string

TempDir is a wrapper around ioutil.TempDir that provides a cleanup function.

func WriteExecutable

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

WriteExecutable ensures that the parent directory exists, and writes an executable with provided content

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, func())

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.

func ContextWithTimeout

func ContextWithTimeout(duration time.Duration) ContextOpt

ContextWithTimeout allows to set provided timeout to 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) Desc

func (f FeatureSet) Desc() string

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

func (FeatureSet) Disable

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

Disable disables all feature flags in the given FeatureSet in the given context. The context is treated as an outgoing context.

type FeatureSets

type FeatureSets []FeatureSet

FeatureSets is a slice containing many FeatureSets

func NewFeatureSets

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

NewFeatureSets takes a slice of go feature flags, and an optional variadic set of ruby feature flags and returns a FeatureSets slice

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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