Documentation ¶
Index ¶
- Constants
- Variables
- func AccTest(t *testing.T, c TestCase)
- func ActivateClient(failNoResponder bool)
- func DeactivateClient()
- func NewMockClient(input MockClientInput) *client.Client
- func RandPrefixString(prefix string, strlen int) string
- func RandString(strlen int) string
- func RandStringFromCharSet(strlen int, charSet string) string
- func RegisterResponder(method, url string, responder Responder)
- type AssertFunc
- type MockClientInput
- type MockTransport
- type Responder
- type Step
- type StepAPICall
- type StepAction
- type StepAssert
- type StepAssertFunc
- type StepAssertSet
- type StepAssertTritonError
- type StepClient
- type TestCase
- type TritonStateBag
Constants ¶
const ( // CharSetAlphaNum is the alphanumeric character set for use with // RandStringFromCharSet CharSetAlphaNum = "abcdefghijklmnopqrstuvwxyz012346789" // CharSetAlpha is the alphabetical character set for use with // RandStringFromCharSet CharSetAlpha = "abcdefghijklmnopqrstuvwxyz" )
const ( StateCancelled = "cancelled" StateHalted = "halted" )
const TestEnvVar = "TRITON_TEST"
Variables ¶
var DefaultMockClient = NewMockClient(MockClientInput{})
DefaultMockClient uses NewMockClient to construct a mocked out client.Client
var DefaultMockTransport = &MockTransport{ responders: make(map[string]Responder), }
DefaultMockTransport allows users to easily and globally alter the default RoundTripper for all http requests.
var NoResponderFound = errors.New("no responder found")
NoResponderFound is returned when no responders are found for a given HTTP method and URL.
Functions ¶
func ActivateClient ¶
func ActivateClient(failNoResponder bool)
Activate replaces the `Transport` on the `http.Client` with our `DefaultMockTransport`.
func DeactivateClient ¶
func DeactivateClient()
Deactivate replaces our `DefaultMockTransport` with the `http.DefaultTransport`.
func NewMockClient ¶
func NewMockClient(input MockClientInput) *client.Client
NewMockClient returns a new client.Client that includes our DefaultMockTransport which allows us to attach custom HTTP client request responders.
func RandPrefixString ¶
RandPrefixString generates a random alphanumeric string of the length specified with the given prefix
func RandString ¶
RandString generates a random alphanumeric string of the length specified
func RandStringFromCharSet ¶
RandStringFromCharSet generates a random string by selecting characters from the charset provided
func RegisterResponder ¶
RegisterResponder adds a responder to the `DefaultMockTransport` responder table.
Types ¶
type AssertFunc ¶
type AssertFunc func(TritonStateBag) error
type MockClientInput ¶
type MockClientInput struct {
AccountName string
}
type MockTransport ¶
type MockTransport struct { FailNoResponder bool // contains filtered or unexported fields }
MockTransport implements http.RoundTripper, which fulfills single http requests issued by an http.Client. This implementation doesn't actually make the call, instead defering to the registered list of responders.
func (*MockTransport) Clear ¶
func (m *MockTransport) Clear()
Clear clears out all the mock responders that have been set on a particular MockTransport object. This comes in especially handy when utilizing the global DefaultMockTRansport and is utilized by the DeactivateClient func.
func (*MockTransport) RegisterResponder ¶
func (m *MockTransport) RegisterResponder(method, url string, responder Responder)
RegisterResponder adds a new responder, associated with a given HTTP method and URL. When a request comes in that matches, the responder will be called and the response returned to the client.
type Step ¶
type Step interface { Run(TritonStateBag) StepAction Cleanup(TritonStateBag) }
type StepAPICall ¶
type StepAPICall struct { StateBagKey string ErrorKey string CallFunc func(client interface{}) (interface{}, error) CleanupFunc func(client interface{}, callState interface{}) }
func (*StepAPICall) Cleanup ¶
func (s *StepAPICall) Cleanup(state TritonStateBag)
func (*StepAPICall) Run ¶
func (s *StepAPICall) Run(state TritonStateBag) StepAction
type StepAssert ¶
func (*StepAssert) Cleanup ¶
func (s *StepAssert) Cleanup(state TritonStateBag)
func (*StepAssert) Run ¶
func (s *StepAssert) Run(state TritonStateBag) StepAction
type StepAssertFunc ¶
type StepAssertFunc struct {
AssertFunc AssertFunc
}
func (*StepAssertFunc) Cleanup ¶
func (s *StepAssertFunc) Cleanup(state TritonStateBag)
func (*StepAssertFunc) Run ¶
func (s *StepAssertFunc) Run(state TritonStateBag) StepAction
type StepAssertSet ¶
func (*StepAssertSet) Cleanup ¶
func (s *StepAssertSet) Cleanup(state TritonStateBag)
func (*StepAssertSet) Run ¶
func (s *StepAssertSet) Run(state TritonStateBag) StepAction
type StepAssertTritonError ¶
func (*StepAssertTritonError) Cleanup ¶
func (s *StepAssertTritonError) Cleanup(state TritonStateBag)
func (*StepAssertTritonError) Run ¶
func (s *StepAssertTritonError) Run(state TritonStateBag) StepAction
type StepClient ¶
type StepClient struct { StateBagKey string ErrorKey string CallFunc func(config *triton.ClientConfig) (interface{}, error) CleanupFunc func(client interface{}, callState interface{}) }
func (*StepClient) Cleanup ¶
func (s *StepClient) Cleanup(state TritonStateBag)
func (*StepClient) Run ¶
func (s *StepClient) Run(state TritonStateBag) StepAction
type TestCase ¶
type TestCase struct { Steps []Step State TritonStateBag }