testtools

package
v0.0.0-...-edbd301 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONValidationSchemaPath = "testdata/valid_output_schema.json"
)

JSONValidationSchemaPath the path in the project to the valid response schema.

Variables

This section is empty.

Functions

func AreFuncsEqual

func AreFuncsEqual(a interface{}, b interface{}) (bool, error)

AreFuncsEqual returns true only if a and b are both functions, and both point to the same function. Returns false and a non-nil error if either argument is not a function. Returns true and a non-nil error if both arguments are nil,

func AreStringSlicesEqual

func AreStringSlicesEqual(a []string, b []string) bool

AreStringSlicesEqual determines if two string slices are equal. Equality distinguishes nil-ness, but not capacity

func CloneStringSlice

func CloneStringSlice(inSlice []string) []string

CloneStringSlice create a non-shared copy of inSlice

func ConformToJSONSchemaFile

func ConformToJSONSchemaFile(schemaURL string) types.GomegaMatcher

ConformToJSONSchemaFile returns a Gomega "custom matcher" to validate a JSON blob against a JSON schema

func GetPEMPublicKeyAlgorithm

func GetPEMPublicKeyAlgorithm(PEMPublicKey string) (x509.PublicKeyAlgorithm, error)

GetPEMPublicKeyAlgorithm determines the PKI algorithm from a given public key string. (When the production code supports verification, this will be moved to a methods of the X509Encoded and PEMEncoded types)

func GetProjectPath

func GetProjectPath(d *deps.Dependencies) (string, error)

GetProjectPath returns the root path of the project (at compile time.)

func GetSourceFilename

func GetSourceFilename(d *deps.Dependencies) (string, error)

GetSourceFilename returns the filename of the caller's source code.

func GetURLFromProjectPath

func GetURLFromProjectPath(d *deps.Dependencies, projPath string) (string, error)

GetURLFromProjectPath converts a project path to a file:/// URL.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a newly allocated copy of the string.

func ValidateJSONSchema

func ValidateJSONSchema(d *deps.Dependencies, responseStr string, schemaPath string) error

ValidateJSONSchema validates that a string containing JSON conforms to the specified schema.

func ValidateResponse

func ValidateResponse(d *deps.Dependencies, responseStr string) (*codechallenge.SignedMessage, x509.PublicKeyAlgorithm, error)

ValidateResponse validates that the string provided conforms to the schema in the spec, has a valid PEM format public key, a valid base64 signature, and that the signature was produced by signing the message with the private key (corresponding to the included public key). It returns the parsed JSON response, the signing algorithm and any errors encountered.

func WrapFuncCallWithCounter

func WrapFuncCallWithCounter(f func()) (func(), *int)

WrapFuncCallWithCounter wraps the provided function, adding a returned pointer to a call counter.

Types

type DummyFileInfo

type DummyFileInfo struct {
	NameVal    string
	SizeVal    int64
	ModeVal    os.FileMode
	ModTimeVal time.Time
}

DummyFileInfo a mock for a os.FileInfo interface.

func (*DummyFileInfo) IsDir

func (dfi *DummyFileInfo) IsDir() bool

IsDir abbreviation for Mode().IsDir()

func (*DummyFileInfo) ModTime

func (dfi *DummyFileInfo) ModTime() time.Time

ModTime modification time

func (*DummyFileInfo) Mode

func (dfi *DummyFileInfo) Mode() os.FileMode

Mode file mode bits

func (*DummyFileInfo) Name

func (dfi *DummyFileInfo) Name() string

Name base name of the file

func (*DummyFileInfo) Size

func (dfi *DummyFileInfo) Size() int64

Size length in bytes for regular files; system-dependent for others

func (*DummyFileInfo) Sys

func (dfi *DummyFileInfo) Sys() interface{}

Sys underlying data source (can return nil)

type ErrorSpec

type ErrorSpec struct {
	Type    string
	Message string
}

ErrorSpec defines the expected value of an error.

func NewErrorSpecFrom

func NewErrorSpecFrom(inErr error) *ErrorSpec

NewErrorSpecFrom returns a *ErrorSpec that matches inErr.

func (*ErrorSpec) EnsureMatches

func (es *ErrorSpec) EnsureMatches(inErr error) error

EnsureMatches returns an error is inErr doesn't match.

func (*ErrorSpec) String

func (es *ErrorSpec) String() string

String returns string representation of es.

type FakeFileSystem

type FakeFileSystem map[string]*string

FakeFileSystem is a representation of the filesystem:

  • all empty leaf directories are represented by a nil
  • all files are represented by a pointer to a string of its contents

func (FakeFileSystem) Clone

func (ffs FakeFileSystem) Clone() FakeFileSystem

Clone makes a deep clone of the FakeFileSystem.

func (FakeFileSystem) IsEqualTo

func (ffs FakeFileSystem) IsEqualTo(other FakeFileSystem) bool

IsEqualTo does a deep comparison of two FakeFileSystems

func (FakeFileSystem) String

func (ffs FakeFileSystem) String() string

String returns a string representation of the FakeFileSystem.

type GenericStringMatcher

type GenericStringMatcher func(string) error

GenericStringMatcher is generic matcher for a string validation function.

func GetResponseMatcherForMessageAndAlgorithm

func GetResponseMatcherForMessageAndAlgorithm(d *deps.Dependencies, msg string, algorithm x509.PublicKeyAlgorithm) GenericStringMatcher

GetResponseMatcherForMessageAndAlgorithm returns a string matcher for a valid response with a specific message and algorithm

func GetResponseMatcherForMessageAndPubKey

func GetResponseMatcherForMessageAndPubKey(d *deps.Dependencies, msg string, pubKey string) GenericStringMatcher

GetResponseMatcherForMessageAndPubKey returns a string matcher for a valid response with a specific message and public key

func (GenericStringMatcher) MatchString

func (gsm GenericStringMatcher) MatchString(s string) error

MatchString returns whether the strings match.

func (GenericStringMatcher) String

func (gsm GenericStringMatcher) String() string

String returns a generic printable representation

type ReaderFunc

type ReaderFunc func([]byte) (int, error)

ReaderFunc is a func that implements the io.Reader interface.

func (ReaderFunc) Read

func (rf ReaderFunc) Read(p []byte) (int, error)

Read implements Read() for ReaderFunc.

type RegexpStringMatcher

type RegexpStringMatcher struct {
	// contains filtered or unexported fields
}

RegexpStringMatcher is a thin wrapper over regexp.Regexp to alter its String() result.

func NewRegexpStringMatcher

func NewRegexpStringMatcher(pattern string) *RegexpStringMatcher

NewRegexpStringMatcher returns a RegexpStringMatcher from the pattern.

func (*RegexpStringMatcher) MatchString

func (rsm *RegexpStringMatcher) MatchString(s string) error

MatchString returns whether the strings match the pattern.

func (*RegexpStringMatcher) String

func (rsm *RegexpStringMatcher) String() string

String returns a printable representation of the regular expression

type StringMatcher

type StringMatcher interface {
	MatchString(string) error
	String() string
}

StringMatcher is an interface for comparing strings.

type StringStringMatcher

type StringStringMatcher struct {
	// contains filtered or unexported fields
}

StringStringMatcher returns StringMatcher only matching itself.

func NewStringStringMatcher

func NewStringStringMatcher(s string) *StringStringMatcher

NewStringStringMatcher returns a new StringStringMatcher from the string s.

func (*StringStringMatcher) MatchString

func (ssm *StringStringMatcher) MatchString(s string) error

MatchString returns whether the strings are equal

func (*StringStringMatcher) String

func (ssm *StringStringMatcher) String() string

String returns a printable representation of the string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL