package testonly

import "github.com/google/trillian/testonly"

Package testonly contains code and data that should only be used by tests. Production code MUST NOT depend on anything in this package. This will be enforced by tools where possible.

As an example PEM encoded test certificates and helper functions to decode them are suitable candidates for being placed in testonly. However, nothing specific to a particular application should be added at this level. Do not add CT specific test data for example.

Index

Constants

const DemoPrivateKey string = "" /* 296 byte string literal not displayed */

DemoPrivateKey is the private key itself; must only be used for testing purposes

const DemoPrivateKeyPass string = "towel"

DemoPrivateKeyPass is the password for DemoPrivateKey

const DemoPublicKey string = "" /* 180 byte string literal not displayed */

DemoPublicKey is the public key that corresponds to DemoPrivateKey.

Functions

func EnsureErrorContains

func EnsureErrorContains(t *testing.T, err error, s string)

EnsureErrorContains checks that an error contains a specific substring and fails a test with a fatal if it does not or the error was nil.

func HashKey

func HashKey(key string) []byte

HashKey converts a map key into a map index using SHA256. This preserves tests that precomputed indexes based on SHA256.

func MustDecodeBase64

func MustDecodeBase64(b64 string) []byte

MustDecodeBase64 expects a base 64 encoded string input and panics if it cannot be decoded

func MustHexDecode

func MustHexDecode(b string) []byte

MustHexDecode decodes its input string from hex and panics if this fails

func MustMarshalAny

func MustMarshalAny(t *testing.T, in proto.Message) *anypb.Any

MustMarshalAny is used in tests to Marshal proto messages into the protobuf.ptypes.anypb.Any used in the Trillian API and in storage. Failure to marshal will fail the test but the suite will continue.

func MustMarshalAnyNoT

func MustMarshalAnyNoT(in proto.Message) []byte

MustMarshalAnyNoT is used to Marshal proto messages into the protobuf.ptypes.anypb.Any used throughout the Trillian API and in storage. Use if testing.T not available. Failure to marshal will fail the test suite.

func MustToTimestampProto

func MustToTimestampProto(t time.Time) *timestamppb.Timestamp

MustToTimestampProto converts t to a Timestamp protobuf, or panics if this fails.

func NewSignerWithErr

func NewSignerWithErr(pubKey crypto.PublicKey, err error) crypto.Signer

NewSignerWithErr creates a signer that always returns err when Sign() is called.

func NewSignerWithFixedSig

func NewSignerWithFixedSig(pubKey crypto.PublicKey, sig []byte) crypto.Signer

NewSignerWithFixedSig creates a signer that always return sig when Sign() is called.

func RelativeToPackage

func RelativeToPackage(p string) string

RelativeToPackage returns the input path p as an absolute path, resolved relative to the caller's package. The working directory for Go tests is the dir of the test file. Using "plain" relative paths in test utilities is, therefore, brittle, as the directory structure may change depending on where the tests are placed.

func TransparentHash

func TransparentHash(key string) []byte

TransparentHash returns a key that can be visually inspected. This supports testing where it was nice to see what the key was.

Types

type MockServer

type MockServer struct {
	Admin       *tmock.MockTrillianAdminServer
	Log         *tmock.MockTrillianLogServer
	AdminClient trillian.TrillianAdminClient
	LogClient   trillian.TrillianLogClient
	Addr        string
}

MockServer implements the TrillianAdminServer, and TrillianLogServer.

func NewMockServer

func NewMockServer(ctrl *gomock.Controller) (*MockServer, func(), error)

NewMockServer starts a server on a random port. Returns the started server, the listener it's using for connection and a close function that must be defer-called on the scope the server is meant to stop.

Source Files

doc.go encoding.go errors.go hasher.go keys.go marshalling.go mock_server.go paths.go signer.go

Directories

PathSynopsis
testonly/flagsaverPackage flagsaver provides a simple way to save and restore flag values.
testonly/integrationPackage integration provides test-only code for performing integrated tests of Trillian functionality.
testonly/integration/etcdPackage etcd contains a helper to start an embedded etcd server.
testonly/matchersPackage matchers contains additional gomock matchers.
testonly/mdmPackage mdm provides test-only code for checking the merge delay of a Trillian log.
testonly/mdm/mdmtestThe mdmtest binary runs merge delay tests against a Trillian Log.
testonly/setupPackage setup contains test-only code that's useful for setting up tests.
testonly/tmockPackage tmock is a generated GoMock package.
Version
v1.7.1 (latest)
Published
Jan 9, 2025
Platform
linux/amd64
Imports
21 packages
Last checked
5 days ago

Tools for package owners.