Documentation ¶
Overview ¶
Package testutils provides various utilities for use in tests.
Index ¶
- func ArtifactGoogleCreds(tb testing.TB) string
- func BackingMongoDBClient(tb testing.TB) *mongo.Client
- func BackingMongoDBURI(tb testing.TB) string
- func GenerateSelfSignedCertificate(commonName string, altNames ...string) (tls.Certificate, string, string, *x509.CertPool, error)
- func NewMongoDBNamespace() (string, string)
- func ReserveRandomListener(tb testing.TB) *net.TCPListener
- func SkipUnlessArtifactGoogleCreds(tb testing.TB)
- func SkipUnlessBackingMongoDBURI(tb testing.TB)
- func SkipUnlessInternet(tb testing.TB)
- func Teardown()
- func TempDir(dir, pattern string) (string, error)
- func TempDirT(tb testing.TB, dir, pattern string) string
- func TempFile(tb testing.TB, name string) *os.File
- func TestMain(t *testing.T, ...)
- func WaitForAssertion(t *testing.T, assertion func(tb testing.TB))
- func WaitForAssertionWithSleep(t *testing.T, wait time.Duration, maxAttempts int, ...)
- func WaitSuccessfulDial(address string) error
- type ContextualMainExecution
- type MainTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArtifactGoogleCreds ¶
ArtifactGoogleCreds returns the google credentials for artifact.
func BackingMongoDBClient ¶
BackingMongoDBClient returns a backing MongoDB client to use.
func BackingMongoDBURI ¶
BackingMongoDBURI returns the backing MongoDB URI to use.
func GenerateSelfSignedCertificate ¶ added in v0.0.3
func GenerateSelfSignedCertificate(commonName string, altNames ...string) (tls.Certificate, string, string, *x509.CertPool, error)
GenerateSelfSignedCertificate generates a self signed certificate with the given names.
func NewMongoDBNamespace ¶
NewMongoDBNamespace returns a new random namespace to use.
func ReserveRandomListener ¶ added in v0.0.5
func ReserveRandomListener(tb testing.TB) *net.TCPListener
ReserveRandomListener returns a new TCP listener at a random port.
func SkipUnlessArtifactGoogleCreds ¶
SkipUnlessArtifactGoogleCreds verifies google credentials are available for artifact.
func SkipUnlessBackingMongoDBURI ¶
SkipUnlessBackingMongoDBURI verifies there is a backing MongoDB URI to use.
func SkipUnlessInternet ¶
SkipUnlessInternet verifies there is an internet connection.
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 ¶
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 WaitForAssertionWithSleep ¶ added in v0.1.5
func WaitForAssertionWithSleep(t *testing.T, wait time.Duration, maxAttempts int, assertion func(tb testing.TB))
WaitForAssertionWithSleep is similar to WaitForAssertion but takes a wait time and maximum number of attempts as parameters.
func WaitSuccessfulDial ¶
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.