Files
pki/Documentation/api/internal_testenv.md

2.5 KiB

testenv

import "github.com/effective-security/xpki/internal/testenv"

Package testenv gates tests that need external fixtures, such as the local-kms emulator or the SoftHSM token (XPKI-100).

A fixture that is not reachable skips the test, unless XPKI_INTEGRATION is "required" (the Makefile exports it, so make test/covtest and CI fail instead). A reachable fixture always runs the test, so a present but broken fixture fails. Unit tests must not call it.

func TestKMS(t *testing.T) {
	testenv.RequireTCP(t, "local-kms", "localhost:14556")
	// ...
}

RequireFile does the same for a fixture identified by a file, such as the SoftHSM token configuration.

Index

Constants

const (
    // IntegrationEnv is the environment variable that selects whether a
    // missing fixture skips or fails a test.
    IntegrationEnv = "XPKI_INTEGRATION"
    // Required is the IntegrationEnv value that makes a missing fixture fail.
    Required = "required"
)

func IntegrationRequired

func IntegrationRequired() bool

IntegrationRequired reports whether a missing fixture must fail the test.

func RequireFile

func RequireFile(t testing.TB, name, path string)

RequireFile gates t on the fixture name whose file is at path, such as the SoftHSM token configuration. It returns when path exists. Otherwise it fails t when IntegrationRequired, and skips t when not. Any stat error other than a missing file fails t, since the fixture is present but broken.

func RequireTCP

func RequireTCP(t testing.TB, name, addr string)

RequireTCP gates t on the fixture name listening at addr ("host:port"). It returns when addr accepts a TCP connection. Otherwise it fails t when IntegrationRequired, and skips t when not.

Generated by gomarkdoc