testjuice

package
v1.17.9 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Description: This package contains helper functions to be used in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertResponse

func AssertResponse(expectedStatusCode int, resp *http.Response, responseBody []byte) error

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 CheckErrorAndFail

func CheckErrorAndFail(t *testing.T, err error)

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

func CheckErrorAndFailWithMessage(t *testing.T, err error, debugMessage string)

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 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.

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.

Jump to

Keyboard shortcuts

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