Documentation ¶
Overview ¶
Package framework contains the low-level implementation of test harness infrastructure that can be reused for different kinds of tests.
The general model is:
1. The test harness communicates with a test service, which exposes a root endpoint for querying its status (GET) or creating some kind of entity within the test service (POST).
2. The test harness can expose any number of mock endpoints to receive requests from the test service.
3. There is a general notion of a test context which is similar to Go's *testing.T, allowing pieces of test logic to be associated with a test identifier and to accumulate success/failure results.
The domain-specific code that knows what is being tested is responsible for providing the parameters to send to the test service, the HTTP handlers for handling requests to mock endpoints, and a domain-specific test API on top of the test context.
Index ¶
- func PrintFilterDescription(harness *TestHarness, filters RegexFilters, allCapabilities []string)
- func PrintResults(results Results)
- type CapturedMessage
- type CapturedOutput
- type CapturingLogger
- type ConsoleTestLogger
- type Context
- func (c *Context) Debug(message string, args ...interface{})
- func (c *Context) DebugLogger() Logger
- func (c *Context) Errorf(format string, args ...interface{})
- func (c *Context) FailNow()
- func (c *Context) ID() TestID
- func (c *Context) Run(name string, action func(*Context))
- func (c *Context) Skip()
- func (c *Context) SkipWithReason(reason string)
- type Filter
- type IncomingRequestInfo
- type Logger
- type MessageSortingQueue
- type MockEndpoint
- type RegexFilters
- type RegexList
- type Results
- type TestFailure
- type TestHarness
- func (h *TestHarness) NewMockEndpoint(handler http.Handler, contextFn func(context.Context) context.Context, ...) *MockEndpoint
- func (h *TestHarness) NewTestServiceEntity(entityParams interface{}, description string, logger Logger) (*TestServiceEntity, error)
- func (h *TestHarness) StopService() error
- func (h *TestHarness) TestServiceHasCapability(desired string) bool
- func (h *TestHarness) TestServiceInfo() TestServiceInfo
- type TestID
- type TestLogger
- type TestResult
- type TestServiceEntity
- type TestServiceInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintFilterDescription ¶
func PrintFilterDescription(harness *TestHarness, filters RegexFilters, allCapabilities []string)
func PrintResults ¶
func PrintResults(results Results)
Types ¶
type CapturedMessage ¶
type CapturedOutput ¶
type CapturedOutput []CapturedMessage
func (CapturedOutput) ToString ¶
func (output CapturedOutput) ToString(prefix string) string
type CapturingLogger ¶
type CapturingLogger struct {
// contains filtered or unexported fields
}
func (*CapturingLogger) Output ¶
func (l *CapturingLogger) Output() CapturedOutput
func (*CapturingLogger) Printf ¶
func (l *CapturingLogger) Printf(message string, args ...interface{})
type ConsoleTestLogger ¶
func (ConsoleTestLogger) TestError ¶
func (c ConsoleTestLogger) TestError(id TestID, err error)
func (ConsoleTestLogger) TestFinished ¶
func (c ConsoleTestLogger) TestFinished(id TestID, failed bool, debugOutput CapturedOutput)
func (ConsoleTestLogger) TestSkipped ¶
func (c ConsoleTestLogger) TestSkipped(id TestID, reason string)
func (ConsoleTestLogger) TestStarted ¶
func (c ConsoleTestLogger) TestStarted(id TestID)
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) DebugLogger ¶
func (*Context) SkipWithReason ¶
type IncomingRequestInfo ¶
type IncomingRequestInfo struct { Headers http.Header Method string Body []byte Context context.Context }
IncomingRequestInfo contains information about an HTTP request sent by the test service to one of the mock endpoints.
type Logger ¶
type Logger interface {
Printf(message string, args ...interface{})
}
func LoggerWithPrefix ¶
func NullLogger ¶
func NullLogger() Logger
type MessageSortingQueue ¶ added in v0.0.5
type MessageSortingQueue struct { C chan []byte // contains filtered or unexported fields }
func NewMessageSortingQueue ¶ added in v0.0.5
func NewMessageSortingQueue(channelSize int) *MessageSortingQueue
func (*MessageSortingQueue) Accept ¶ added in v0.0.5
func (q *MessageSortingQueue) Accept(counter int, message []byte)
func (*MessageSortingQueue) Close ¶ added in v0.0.5
func (q *MessageSortingQueue) Close()
func (*MessageSortingQueue) Deferred ¶ added in v0.0.5
func (q *MessageSortingQueue) Deferred() [][]byte
type MockEndpoint ¶
type MockEndpoint struct {
// contains filtered or unexported fields
}
MockEndpoint represents an endpoint that can receive requests.
func (*MockEndpoint) ActiveConnection ¶ added in v0.0.5
func (e *MockEndpoint) ActiveConnection() *IncomingRequestInfo
func (*MockEndpoint) AwaitConnection ¶
func (e *MockEndpoint) AwaitConnection(timeout time.Duration) (IncomingRequestInfo, error)
AwaitConnection waits for an incoming request to the endpoint.
func (*MockEndpoint) BaseURL ¶
func (e *MockEndpoint) BaseURL() string
BaseURL returns the base path of the mock endpoint.
func (*MockEndpoint) Close ¶
func (e *MockEndpoint) Close()
Close unregisters the endpoint. Any subsequent requests to it will receive 404 errors. It also cancels the Context for every active request to that endpoint.
type RegexFilters ¶
func (RegexFilters) AsFilter ¶
func (r RegexFilters) AsFilter(id TestID) bool
type Results ¶
type Results struct { Tests []TestResult Failures []TestResult }
type TestFailure ¶
func (TestFailure) Error ¶
func (f TestFailure) Error() string
type TestHarness ¶
type TestHarness struct {
// contains filtered or unexported fields
}
func NewTestHarness ¶
func NewTestHarness( testServiceBaseURL string, testHarnessExternalHostname string, testHarnessPort int, statusQueryTimeout time.Duration, debugLogger Logger, startupOutput io.Writer, ) (*TestHarness, error)
NewTestHarness creates a TestHarness instance, and verifies that the test service is responding by querying its status resource. It also starts an HTTP listener on the specified port to receive callback requests.
func (*TestHarness) NewMockEndpoint ¶
func (h *TestHarness) NewMockEndpoint( handler http.Handler, contextFn func(context.Context) context.Context, logger Logger, ) *MockEndpoint
NewMockEndpoint adds a new endpoint that can receive requests.
The specified handler will be called for all incoming requests to the endpoint's base URL or any subpath of it. For instance, if the generated base URL (as reported by MockEndpoint.BaseURL()) is http://localhost:8111/endpoints/3, then it can also receive requests to http://localhost:8111/endpoints/3/some/subpath.
When the handler is called, the test harness rewrites the request URL first so that the handler sees only the subpath. It also attaches a Context to the request whose Done channel will be closed if Close is called on the endpoint.
func (*TestHarness) NewTestServiceEntity ¶
func (h *TestHarness) NewTestServiceEntity( entityParams interface{}, description string, logger Logger, ) (*TestServiceEntity, error)
NewTestServiceEntity tells the test service to create a new instance of whatever kind of entity it manages, based on the parameters we provide. The test harness can interact with it via the returned TestServiceEntity. The entity is assumed to remain active inside the test service until we explicitly close it.
The format of entityParams is defined by the test harness; this low-level method simply calls json.Marshal to convert whatever it is to JSON.
func (*TestHarness) StopService ¶ added in v0.0.3
func (h *TestHarness) StopService() error
StopService tells the test service that it should exit.
func (*TestHarness) TestServiceHasCapability ¶
func (h *TestHarness) TestServiceHasCapability(desired string) bool
func (*TestHarness) TestServiceInfo ¶
func (h *TestHarness) TestServiceInfo() TestServiceInfo
type TestLogger ¶
type TestResult ¶
type TestServiceEntity ¶
type TestServiceEntity struct {
// contains filtered or unexported fields
}
TestServiceEntity represents some kind of entity that we have asked the test service to create, which the test harness will interact with.
func (*TestServiceEntity) Close ¶
func (e *TestServiceEntity) Close() error
Close tells the test service to dispose of this entity.
func (*TestServiceEntity) SendCommand ¶
func (e *TestServiceEntity) SendCommand(command string, additionalParams ...map[string]interface{}) error
SendCommand sends a command to the test service entity.
type TestServiceInfo ¶
type TestServiceInfo struct { Description string `json:"description"` Capabilities []string `json:"capabilities"` }
TestServiceInfo is status information returned by the test service from the initial status query.