Documentation
¶
Index ¶
- Constants
- func EncodeED25519PrivateKey(tb testing.TB, privateKey ed25519.PrivateKey) string
- func EncodeED25519PublicKey(tb testing.TB, publicKey ed25519.PublicKey) string
- func EncodeRSAPrivateKey(t *testing.T, privateKey *rsa.PrivateKey) string
- func EncodeRSAPublicKey(t *testing.T, publicKey *rsa.PublicKey) string
- func FreePort(tb testing.TB) int
- func FreePorts(tb testing.TB, n int) []int
- func GenerateED25519KeyPair(tb testing.TB) (public, private string)
- func GenerateED25519PrivateKey(tb testing.TB) ed25519.PrivateKey
- func GenerateED25519PublicKey(tb testing.TB, privateKey ed25519.PrivateKey, filePath string)
- func GenerateRSAKeyPair(t *testing.T) (public, private string)
- func GenerateRSAPrivateKey(t *testing.T) *rsa.PrivateKey
- func GenerateRSAPublicKey(t *testing.T, privateKey *rsa.PrivateKey, filePath string)
- func SkipTags(tags ...tagx.Tag) bool
- func Tags(tb testing.TB, tags ...tagx.Tag)
- func WaitForFreePorts(tb testing.TB, ports ...int)
- type ExampleTB
- func (t *ExampleTB) ArtifactDir() string
- func (t *ExampleTB) Attr(_, _ string)
- func (t *ExampleTB) Chdir(dir string)
- func (t *ExampleTB) Cleanup(_ func())
- func (t *ExampleTB) Context() context.Context
- func (t *ExampleTB) Error(args ...any)
- func (t *ExampleTB) Errorf(format string, args ...any)
- func (t *ExampleTB) Fail()
- func (t *ExampleTB) FailNow()
- func (t *ExampleTB) Failed() bool
- func (t *ExampleTB) Fatal(args ...any)
- func (t *ExampleTB) Fatalf(format string, args ...any)
- func (t *ExampleTB) Helper()
- func (t *ExampleTB) Log(args ...any)
- func (t *ExampleTB) Logf(format string, args ...any)
- func (t *ExampleTB) Name() string
- func (t *ExampleTB) Output() io.Writer
- func (t *ExampleTB) Run(name string, f func(testing.TB)) bool
- func (t *ExampleTB) Setenv(key, value string)
- func (t *ExampleTB) Skip(args ...any)
- func (t *ExampleTB) SkipNow()
- func (t *ExampleTB) Skipf(format string, args ...any)
- func (t *ExampleTB) Skipped() bool
- func (t *ExampleTB) TempDir() string
- type M
- type MFunc
Examples ¶
Constants ¶
const EnvTestTags = "GO_TEST_TAGS"
Variables ¶
This section is empty.
Functions ¶
func EncodeED25519PrivateKey ¶ added in v0.2.0
func EncodeED25519PrivateKey(tb testing.TB, privateKey ed25519.PrivateKey) string
EncodeED25519PrivateKey encodes an ED25519 private key to PEM format.
func EncodeED25519PublicKey ¶ added in v0.2.0
EncodeED25519PublicKey encodes an ED25519 public key to PEM format.
func EncodeRSAPrivateKey ¶ added in v0.2.0
func EncodeRSAPrivateKey(t *testing.T, privateKey *rsa.PrivateKey) string
EncodeRSAPrivateKey encodes an RSA private key to PEM format.
func EncodeRSAPublicKey ¶ added in v0.2.0
EncodeRSAPublicKey encodes an RSA public key to PEM format.
func GenerateED25519KeyPair ¶ added in v0.2.0
GenerateED25519KeyPair generates a new ED25519 key pair and returns the paths to the public and private key files.
Example usage:
func TestExample(t *testing.T) {
publicKeyPath, privateKeyPath := GenerateED25519KeyPair(t)
// Use the key paths for testing crypto operations
// Files are automatically cleaned up when test completes
}
func GenerateED25519PrivateKey ¶ added in v0.2.0
func GenerateED25519PrivateKey(tb testing.TB) ed25519.PrivateKey
GenerateED25519PrivateKey generates a new ED25519 private key.
func GenerateED25519PublicKey ¶ added in v0.2.0
func GenerateED25519PublicKey(tb testing.TB, privateKey ed25519.PrivateKey, filePath string)
GenerateED25519PublicKey generates a new public key from an ED25519 private key and writes it to a file.
func GenerateRSAKeyPair ¶ added in v0.2.0
GenerateRSAKeyPair generates a new RSA key pair and returns the paths to the public and private key files.
Example usage:
func TestExample(t *testing.T) {
publicKeyPath, privateKeyPath := GenerateRSAKeyPair(t)
// Use the key paths for testing crypto operations
// Files are automatically cleaned up when test completes
}
func GenerateRSAPrivateKey ¶ added in v0.2.0
func GenerateRSAPrivateKey(t *testing.T) *rsa.PrivateKey
GenerateRSAPrivateKey generates a new RSA private key.
func GenerateRSAPublicKey ¶ added in v0.2.0
func GenerateRSAPublicKey(t *testing.T, privateKey *rsa.PrivateKey, filePath string)
GenerateRSAPublicKey generates a new public key from an RSA private key and writes it to a file.
func Tags ¶
Tags defines the tags that the test should run under.
For example:
func TestDemo(t *testing.T) {
testing.Tags(t, tagx.Integration, tagx.Short)
}
Results being run with:
- no tags
- `GO_TEST_TAGS=fast`
- `GO_TEST_TAGS=integration`
- `GO_TEST_TAGS=fast,integration`
But would be skipped with:
- `GO_TEST_TAGS=-fast`
- `GO_TEST_TAGS=-integration`
- `GO_TEST_TAGS=fast,-integration`
func WaitForFreePorts ¶ added in v0.11.0
WaitForFreePorts returns a free port on localhost
Types ¶
type ExampleTB ¶ added in v0.9.0
type ExampleTB struct {
testing.TB // nil embed ok for examples
// contains filtered or unexported fields
}
func NewExampleTB ¶ added in v0.9.0
func NewExampleTB() *ExampleTB
NewExampleTB creates one for examples
Example ¶
package main
import (
"testing"
testingx "github.com/foomo/go/testing"
)
func helper(tb testing.TB) {
tb.Helper()
tb.Log("log called")
tb.Logf("logf called with tb: %T", tb)
tb.Error("error called")
tb.Errorf("error called with tb: %T", tb)
}
func main() {
tb := testingx.NewExampleTB()
helper(tb)
}
Output: log called logf called with tb: *testing.ExampleTB error: error called error: error: error called with tb: *testing.ExampleTB
func (*ExampleTB) ArtifactDir ¶ added in v0.9.0
type M ¶ added in v0.7.0
type M interface {
Run() int
}
M is an interface representing the testing.M type, which is used for customizing the behavior of TestMain.