testutils

package
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package testutils provides various utilities for use in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArtifactGoogleCreds

func ArtifactGoogleCreds(t *testing.T) string

ArtifactGoogleCreds returns the google credentials for artifact.

func BackingMongoDBClient

func BackingMongoDBClient(t *testing.T) *mongo.Client

BackingMongoDBClient returns a backing MongoDB client to use.

func BackingMongoDBURI

func BackingMongoDBURI(t *testing.T) string

BackingMongoDBURI returns the backing MongoDB URI to use.

func NewMongoDBNamespace

func NewMongoDBNamespace() (string, string)

NewMongoDBNamespace returns a new random namespace to use.

func SkipUnlessArtifactGoogleCreds

func SkipUnlessArtifactGoogleCreds(t *testing.T)

SkipUnlessArtifactGoogleCreds verifies google credentials are available for artifact.

func SkipUnlessBackingMongoDBURI

func SkipUnlessBackingMongoDBURI(t *testing.T)

SkipUnlessBackingMongoDBURI verifies there is a backing MongoDB URI to use.

func SkipUnlessInternet

func SkipUnlessInternet(t *testing.T)

SkipUnlessInternet verifies there is an internet connection.

func Teardown

func Teardown()

Teardown cleans up any temporary resources used by tests.

func TempDir

func TempDir(dir, pattern string) (string, error)

TempDir creates a temporary directory and fails the test if it cannot.

func TempDirT

func TempDirT(t *testing.T, dir, pattern string) string

TempDirT creates a temporary directory and fails the test if it cannot.

func TestMain

func TestMain(t *testing.T, mainWithArgs func(ctx context.Context, args []string, logger golog.Logger) error, tcs []MainTestCase)

TestMain tests a main function with a series of test cases in serial.

func WaitForAssertion

func WaitForAssertion(t *testing.T, assertion func(tb testing.TB))

WaitForAssertion waits for a testify.Assertion to succeed or ultimately fail. Note: This should only be used if there's absolutely no way to have the test code be able to be signaled that the assertion is ready to be checked. That is, if waiting with respect time is critical, it's okay to use this.

func WaitSuccessfulDial

func WaitSuccessfulDial(address string) error

WaitSuccessfulDial waits for a dial attempt to succeed.

Types

type ContextualMainExecution

type ContextualMainExecution struct {
	Ready       <-chan struct{}
	Done        <-chan error
	Start       func()
	Stop        func()
	QuitSignal  func(t *testing.T)             // reflects syscall.SIGQUIT
	ExpectIters func(t *testing.T, amount int) // expect a certain amount of iters
	WaitIters   func(t *testing.T)             // waits for iters defined by ExpectIters
}

ContextualMainExecution reflects the execution of a main function that can have its lifecycle partially controlled.

func ContextualMain

func ContextualMain(main func(ctx context.Context, args []string, logger golog.Logger) error, args []string, logger golog.Logger) ContextualMainExecution

ContextualMain calls a main entry point function with a cancellable context via the returned execution struct. The main function is run in a separate goroutine.

type MainTestCase

type MainTestCase struct {
	Name   string
	Args   []string
	Err    string
	Before func(t *testing.T, logger golog.Logger, exec *ContextualMainExecution)
	During func(ctx context.Context, t *testing.T, exec *ContextualMainExecution)
	After  func(t *testing.T, logs *observer.ObservedLogs)
}

MainTestCase describes how to execute a main function and what to expect from it.

Directories

Path Synopsis
Package testutilsext is purely for test utilities that may access other packages in the codebase that tend to use testutils.
Package testutilsext is purely for test utilities that may access other packages in the codebase that tend to use testutils.

Jump to

Keyboard shortcuts

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