Skip to main content

testingx

import "github.com/go-softwarelab/common/pkg/testingx"

Package testingx provides set of utilities for tests and runnable examples.

type AssertTB​

AssertTB is a subinterface of testing.TB that fulfills the needs of assert package from testify library, but also includes the Helper method. This package also provides an implementation of this interface, called testingx.E, that can be used in runnable examples.

type AssertTB interface {
Helper()
Errorf(format string, args ...interface{})
}

type E​

E is emulating a testing.TB for runnable examples. It is useful to show usage of the library elements dedicated to tests, how they can be used. Unfortunately, testing.TB cannot be implemented because it has a private method on the interface. This is why it's preferable to use one of testingx or own declared interfaces as argument types instead.

WARNING: This struct is still under development, and still some parts are not implemented completely.

type E struct {
Verbose bool
// This is a hack to make it compatible with testing.TB,
// it shouldn't be ever instantiated, as we're overriding all the methods needed.
*testing.T
}

*E.Chdir​

func (e *E) Chdir(dir string)

Chdir is a testing.TB Chdir method implementation for runnable examples.

*E.Cleanup​

func (e *E) Cleanup(f func())

Cleanup is a testing.TB Cleanup method implementation for runnable examples.

*E.Context​

func (e *E) Context() context.Context

Context is a testing.TB Context method implementation for runnable examples.

*E.Error​

func (e *E) Error(args ...any)

Error is a testing.TB Error method implementation for runnable examples. It writes the error message with "ERROR:" prefix.

*E.Errorf​

func (e *E) Errorf(format string, args ...interface{})

Errorf is a testing.TB Errorf method implementation for runnable examples. It writes the error message with "ERROR:" prefix.

*E.Fail​

func (e *E) Fail()

Fail is a testing.TB Fail method implementation for runnable examples.

*E.FailNow​

func (e *E) FailNow()

FailNow is a testing.TB FailNow method implementation for runnable examples.

*E.Failed​

func (e *E) Failed() bool

Failed is a testing.TB Failed method implementation for runnable examples.

*E.Fatal​

func (e *E) Fatal(args ...any)

Fatal is a testing.TB Fatal method implementation for runnable examples.

*E.Fatalf​

func (e *E) Fatalf(format string, args ...any)

Fatalf is a testing.TB Fatalf method implementation for runnable examples.

*E.Helper​

func (e *E) Helper()

Helper is a testing.TB Helper method implementation for runnable examples.

*E.Log​

func (e *E) Log(args ...any)

Log is a testing.TB Log method implementation for runnable examples.

*E.Logf​

func (e *E) Logf(format string, args ...any)

Logf is a testing.TB Logf method implementation for runnable examples.

*E.Name​

func (e *E) Name() string

Name is a testing.TB Name method implementation for runnable examples.

*E.Setenv​

func (e *E) Setenv(key, value string)

Setenv is a testing.TB Setenv method implementation for runnable examples.

*E.Skip​

func (e *E) Skip(args ...any)

Skip is a testing.TB Skip method implementation for runnable examples.

*E.SkipNow​

func (e *E) SkipNow()

SkipNow is a testing.TB SkipNow method implementation for runnable examples.

*E.Skipf​

func (e *E) Skipf(format string, args ...any)

Skipf is a testing.TB Skipf method implementation for runnable examples.

*E.Skipped​

func (e *E) Skipped() bool

Skipped is a testing.TB Skipped method implementation for runnable examples.

*E.TempDir​

func (e *E) TempDir() string

TempDir is a testing.TB TempDir method implementation for runnable examples.

type PrintingTBE​

PrintingTBE is a subinterface of testing.TB that provides the printing methods of testing.TB (Log, Logf, Error, Errorf) and the Helper method.

type PrintingTBE interface {
Helper()
Errorf(format string, args ...interface{})
Error(args ...any)
Log(args ...any)
Logf(format string, args ...any)
}

type RequireTB​

RequireTB is a subinterface of testing.TB that fulfills the needs of require package from testify library, but also includes the FailNow method. This package also provides an implementation of this interface, called testingx.E, that can be used in runnable examples.

type RequireTB interface {
AssertTB
FailNow()
}

type TB​

TB is a copy of testing.TB interface, that also allows for implementing it. This package also provides an implementation of this interface, called testingx.E, that can be used in runnable examples.

type TB interface {
Cleanup(func())
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
Fatal(args ...any)
Fatalf(format string, args ...any)
Helper()
Log(args ...any)
Logf(format string, args ...any)
Name() string
Setenv(key, value string)
Chdir(dir string)
Skip(args ...any)
SkipNow()
Skipf(format string, args ...any)
Skipped() bool
TempDir() string
Context() context.Context
}

type TBE​

TBE is a subinterface that gives reasonable minimum set of methods from testing.TB, that can be used in tests and runnable examples.

type TBE interface {
PrintingTBE
FailNow()
}