Documentation ¶
Index ¶
- func Assert(tb testing.TB, condition bool, msg string, v ...interface{})
- func Equals(tb testing.TB, exp, act interface{})
- func Includes(tb testing.TB, exp string, act ...string)
- func IncludesI(tb testing.TB, exp string, act ...string)
- func IncludesMap(tb testing.TB, exp, act interface{})
- func IncludesSlice(tb testing.TB, exp, act interface{})
- func NewMockServer(rec MockRecorder, procedures ...MockServerProcedure) *httptest.Server
- func Nil(tb testing.TB, something interface{})
- func NotIncludes(tb testing.TB, exp string, act ...string)
- func NotNil(tb testing.TB, anything interface{})
- func NotZero(tb testing.TB, anything interface{})
- func OK(tb testing.TB, err error)
- func Zero(tb testing.TB, anything interface{})
- type MockAssertion
- type MockRecorder
- type MockResponse
- type MockServerProcedure
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert fails the test if the condition is false.
func Equals ¶
Equals fails the test if exp is not equal to act.
func Includes ¶
Includes fails if expected string is NOT included in the actual string
func IncludesI ¶
IncludesI fails if expected string is NOT included in the actuall string (ignore case)
func IncludesMap ¶
IncludesMap fails if all of expected map entries are NOT included in the actuall map
func IncludesSlice ¶
IncludesSlice fails if all of expected items is NOT included in the actual slice
func NewMockServer ¶
func NewMockServer(rec MockRecorder, procedures ...MockServerProcedure) *httptest.Server
NewMockServer return a mock HTTP server to test requests
func Nil ¶
Nil fails the test if something is NOT nil.
func NotIncludes ¶
NotIncludes fails if expected string is included in the actual string
func NotNil ¶
NotNil fails the test if anything is nil.
func NotZero ¶
NotZero fails the test if anything is NOT nil.
Types ¶
type MockAssertion ¶
type MockAssertion struct {
// contains filtered or unexported fields
}
MockAssertion represents a common assertion for requests
func (*MockAssertion) Body ¶
func (m *MockAssertion) Body(uri, method string) [][]byte
Body returns request body
Example ¶
package main import ( "bytes" "fmt" "net/http" "git.ewintr.nl/go-kit/test" ) func main() { var record test.MockAssertion uri := "/" server := test.NewMockServer(&record, test.MockServerProcedure{ URI: uri, HTTPMethod: http.MethodPost, }) http.Post(server.URL, "text/plain", bytes.NewBufferString("hi there")) for _, b := range record.Body(uri, http.MethodPost) { fmt.Println(string(b)) } }
Output: hi there
func (*MockAssertion) Headers ¶
func (m *MockAssertion) Headers(uri, method string) []http.Header
Headers returns a slice of request headers
Example ¶
package main import ( "fmt" "net/http" "git.ewintr.nl/go-kit/test" ) func main() { var record test.MockAssertion uri := "/" server := test.NewMockServer(&record, test.MockServerProcedure{ URI: uri, HTTPMethod: http.MethodPost, }) http.Post(server.URL, "application/json", nil) fmt.Println(record.Headers(uri, http.MethodPost)) }
Output: [map[Content-Type:[application/json]]]
func (*MockAssertion) Hits ¶
func (m *MockAssertion) Hits(uri, method string) int
Hits returns the number of hits for a uri and method
Example ¶
package main import ( "fmt" "net/http" "git.ewintr.nl/go-kit/test" ) func main() { var record test.MockAssertion uri := "/" server := test.NewMockServer(&record, test.MockServerProcedure{ URI: uri, HTTPMethod: http.MethodGet, }) http.Get(server.URL) fmt.Println(record.Hits(uri, http.MethodGet)) }
Output: 1
func (*MockAssertion) Record ¶
func (m *MockAssertion) Record(r *http.Request)
Record records request hit information
func (*MockAssertion) Reset ¶
func (m *MockAssertion) Reset() error
Reset sets all unexpected properties to their zero value
type MockRecorder ¶
MockRecorder provides a way to record request information from every successful request.
type MockResponse ¶
MockResponse represents a response for the mock server to serve
type MockServerProcedure ¶
type MockServerProcedure struct { URI string HTTPMethod string Response MockResponse }