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
- func EnsureErrorContains(t *testing.T, err error, s string)
- func ExtraDataForValue(value []byte, sz uint) []byte
- func HashKey(key string) []byte
- func MustDecodeBase64(b64 string) []byte
- func MustHexDecode(b string) []byte
- func MustMarshalAny(t *testing.T, in proto.Message) *any.Any
- func MustMarshalAnyNoT(in proto.Message) []byte
- func MustToTimestampProto(t time.Time) *tspb.Timestamp
- func NewSignerWithErr(pubKey crypto.PublicKey, err error) crypto.Signer
- func NewSignerWithFixedSig(pubKey crypto.PublicKey, sig []byte) crypto.Signer
- func RelativeToPackage(p string) string
- func TransparentHash(key string) []byte
- type ErrInvariant
- type MapContents
- func (m *MapContents) CheckContents(leafInclusions []*trillian.MapLeafInclusion, extraSize uint) error
- func (m *MapContents) Empty() bool
- func (m *MapContents) PickKey(prng *rand.Rand) []byte
- func (m *MapContents) RootHash(treeID int64, hasher hashers.MapHasher) ([]byte, error)
- func (m *MapContents) String() string
- func (m *MapContents) UpdatedWith(rev uint64, leaves []*trillian.MapLeaf) *MapContents
- type MockServer
- type VersionedMapContents
- func (p *VersionedMapContents) Empty() bool
- func (p *VersionedMapContents) LastCopy() *MapContents
- func (p *VersionedMapContents) PickCopy(prng *rand.Rand) *MapContents
- func (p *VersionedMapContents) PrevCopy(which int) *MapContents
- func (p *VersionedMapContents) UpdateContentsWith(rev uint64, leaves []*trillian.MapLeaf) (*MapContents, error)
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 ¶
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 ExtraDataForValue ¶
ExtraDataForValue builds a deterministic value for the extra data to be associated with a given value.
func HashKey ¶
HashKey converts a map key into a map index using SHA256. This preserves tests that precomputed indexes based on SHA256.
func MustDecodeBase64 ¶
MustDecodeBase64 expects a base 64 encoded string input and panics if it cannot be decoded
func MustHexDecode ¶
MustHexDecode decodes its input string from hex and panics if this fails
func MustMarshalAny ¶
MustMarshalAny is used in tests to Marshal proto messages into the protobuf.ptypes.any.Any used in the Trillian API and in storage. Failure to marshal will fail the test but the suite will continue.
func MustMarshalAnyNoT ¶
MustMarshalAnyNoT is used to Marshal proto messages into the protobuf.ptypes.any.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 ¶
MustToTimestampProto converts t to a Timestamp protobuf, or panics if this fails.
func NewSignerWithErr ¶
NewSignerWithErr creates a signer that always returns err when Sign() is called.
func NewSignerWithFixedSig ¶
NewSignerWithFixedSig creates a signer that always return sig when Sign() is called.
func RelativeToPackage ¶
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 ¶
TransparentHash returns a key that can be visually inspected. This supports testing where it was nice to see what the key was.
Types ¶
type ErrInvariant ¶
type ErrInvariant struct {
// contains filtered or unexported fields
}
ErrInvariant indicates that an invariant check failed, with details in msg.
func (ErrInvariant) Error ¶
func (e ErrInvariant) Error() string
type MapContents ¶
type MapContents struct { Rev int64 // contains filtered or unexported fields }
MapContents is a complete copy of the map's contents at a particular revision.
func (*MapContents) CheckContents ¶
func (m *MapContents) CheckContents(leafInclusions []*trillian.MapLeafInclusion, extraSize uint) error
CheckContents compares information returned from the Map against a local copy of the map's contents.
func (*MapContents) Empty ¶
func (m *MapContents) Empty() bool
Empty indicates if the contents are empty.
func (*MapContents) PickKey ¶
func (m *MapContents) PickKey(prng *rand.Rand) []byte
PickKey randomly selects a key that already exists in a given copy of the map's contents. Assumes that the copy is non-empty.
func (*MapContents) RootHash ¶
RootHash performs a slow and simple calculation of the root hash for a sparse Merkle tree with the given leaf contents.
func (*MapContents) String ¶
func (m *MapContents) String() string
func (*MapContents) UpdatedWith ¶
func (m *MapContents) UpdatedWith(rev uint64, leaves []*trillian.MapLeaf) *MapContents
UpdatedWith returns a new MapContents object that has been updated to include the given leaves and revision. A nil receiver object is allowed.
type MockServer ¶
type MockServer struct { Admin *tmock.MockTrillianAdminServer Log *tmock.MockTrillianLogServer Map *tmock.MockTrillianMapServer AdminClient trillian.TrillianAdminClient LogClient trillian.TrillianLogClient MapClient trillian.TrillianMapClient Addr string }
MockServer implements the TrillianAdminServer, the TrillianMapServer, 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.
type VersionedMapContents ¶
type VersionedMapContents struct {
// contains filtered or unexported fields
}
VersionedMapContents holds a collection of copies of a Map's contents across different revisions.
func (*VersionedMapContents) Empty ¶
func (p *VersionedMapContents) Empty() bool
Empty indicates whether the most recent map contents are empty.
func (*VersionedMapContents) LastCopy ¶
func (p *VersionedMapContents) LastCopy() *MapContents
LastCopy returns the most recent copy of the map's contents.
func (*VersionedMapContents) PickCopy ¶
func (p *VersionedMapContents) PickCopy(prng *rand.Rand) *MapContents
PickCopy returns a previous copy of the map's contents at random, returning nil if there are no local copies.
func (*VersionedMapContents) PrevCopy ¶
func (p *VersionedMapContents) PrevCopy(which int) *MapContents
PrevCopy returns the specified copy of the map's contents.
func (*VersionedMapContents) UpdateContentsWith ¶
func (p *VersionedMapContents) UpdateContentsWith(rev uint64, leaves []*trillian.MapLeaf) (*MapContents, error)
UpdateContentsWith stores a new copy of the Map's contents, updating the most recent copy with the given leaves. Returns the updated contents.
Source Files ¶
doc.go encoding.go errors.go hasher.go keys.go mapcontents.go marshalling.go mock_server.go paths.go signer.go
Directories ¶
Path | Synopsis |
---|---|
testonly/flagsaver | Package flagsaver provides a simple way to save and restore flag values. |
testonly/hammer | |
testonly/hammer/maphammer | maphammer is a stress/load test for a Trillian Map. |
testonly/hammer/mapreplay | mapreplay replays a log of Trillian Map requests. |
testonly/integration | Package integration provides test-only code for performing integrated tests of Trillian functionality. |
testonly/integration/etcd | |
testonly/matchers | Package matchers contains additional gomock matchers. |
testonly/mdm | Package mdm provides test-only code for checking the merge delay of a Trillian log. |
testonly/mdm/mdmtest | The mdmtest binary runs merge delay tests against a Trillian Log. |
testonly/setup | |
testonly/tmock | Package tmock is a generated GoMock package. |
- Version
- v1.3.1
- Published
- Aug 16, 2019
- Platform
- js/wasm
- Imports
- 29 packages
- Last checked
- 6 hours ago –
Tools for package owners.