Documentation ¶
Overview ¶
Description: This package contains helper functions to be used in tests.
Index ¶
- Constants
- func AssertResponse(expectedStatusCode int, resp *http.Response, responseBody []byte) error
- func AssertStatuses(acceptedStatuses []int, resp *http.Response, responseBody []byte) error
- func CheckErrorAndFail(t *testing.T, err error)
- func CheckErrorAndFailWithMessage(t *testing.T, err error, debugMessage string)
- func LogTest(t *testing.T, responseBody []byte, ...) error
- func NewMockPubSubPayload(message *pubsub.Message, subscriptionMockValue string) (*bytes.Buffer, error)
- func RetrieveObjectIDFromResponse(t *testing.T, responseBody []byte, idField string, ...) error
- func RetrieveStringFromResponse(t *testing.T, responseBody []byte, stringField string, appendTo *[]string, ...) error
- func WaitForServer(url string, timeout time.Duration) error
- type PubSubMessage
- type PubSubPayload
Constants ¶
const ( MongoIDKey string = "_id" RequestMsg string = "| Request 🌎 |" ResponseMsg string = "| Response 📮 |" )
Variables ¶
This section is empty.
Functions ¶
func AssertResponse ¶
AssertResponse is a function that checks if the status code of an HTTP response matches the expected status code.
It takes an expected status code, an HTTP response, and a response body as parameters.
If the status code of the response does not match the expected status code, it returns an error with a message indicating the expected and actual status codes and the response body.
If the status code of the response matches the expected status code, it returns nil.
func AssertStatuses ¶ added in v1.17.10
AssertStatuses is a function that checks if the status code of an HTTP response matches any of the accepted status codes.
It takes a slice of accepted status codes, an HTTP response, and a response body as parameters.
If the status code of the response matches any of the accepted status codes, it returns nil.
If the status code of the response does not match any of the accepted status codes, it returns an error with a message indicating the accepted status codes and the actual status code and response body.
func CheckErrorAndFail ¶
CheckErrorAndFail is a function that checks if an error is not nil and fails the test if it is.
It takes a testing.T and an error as parameters.
If the error is not nil, it calls t.Fatalf with the error message, causing the test to fail.
This function is intended to be used with a test level (global) error field.
func CheckErrorAndFailWithMessage ¶
CheckErrorAndFail is a function that checks if an error is not nil and fails the test if it is.
It takes a testing.T and an error as parameters.
If the error is not nil, it calls t.Fatalf with the error message, causing the test to fail.
This function is intended to be used with a test level (global) error field.
func LogTest ¶ added in v1.33.0
func LogTest(t *testing.T, responseBody []byte, method, URL, testMessage, testCaseName, collectionName, testDescription string) error
LogTest logs the request/response body in a formatted JSON.
It constructs a detailed log message containing information about the HTTP method, URL, and a formatted version of the response body. Returns an error if JSON formatting fails.
func NewMockPubSubPayload ¶
func NewMockPubSubPayload(message *pubsub.Message, subscriptionMockValue string) (*bytes.Buffer, error)
EncodePubSubMessage encodes a Google Pub/Sub message to a bytes.Buffer to use it as a request body in tests.
func RetrieveObjectIDFromResponse ¶ added in v1.31.0
func RetrieveObjectIDFromResponse(t *testing.T, responseBody []byte, idField string, appendTo *[]primitive.ObjectID, bypass bool) error
RetrieveObjectIDFromResponse extracts primitive.ObjectIDs from a response body and append them to a slice for later use.
Types ¶
type PubSubMessage ¶
type PubSubMessage struct { Data []byte `json:"data,omitempty"` Attributes map[string]string `json:"attributes,omitempty"` MessageID string `json:"messageId,omitempty"` PublishTime time.Time `json:"publishTime,omitempty"` }
PubSubMessage is the model for a Google Pub/Sub message.
type PubSubPayload ¶
type PubSubPayload struct { Message PubSubMessage `json:"message,omitempty"` Subscription string `json:"subscription,omitempty"` }
PubSubPayload is the model for a Google Pub/Sub payload.