test

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MockUsers = []map[string]string{
	{
		"username":   "mateotest",
		"email":      "mateo@test.com",
		"restricted": "true",
	},
	{
		"username":   "mateotest2",
		"email":      "mateo@test2.com",
		"restricted": "false",
	},
}

MockUsers contains sample user data for testing purposes.

Functions

func CreateMockResponse

func CreateMockResponse(fileName string) *http.Response

CreateMockResponse creates a mock HTTP response from a JSON file.

func CreateMockResponseBody

func CreateMockResponseBody(fileName string) io.ReadCloser

CreateMockResponseBody creates an io.ReadCloser from a mock JSON file.

func NewTestClient

func NewTestClient(response *http.Response, err error) *client.Client

NewTestClient creates a test client with mock HTTP transport.

func ReadFile

func ReadFile(fileName string) string

ReadFile reads a file from the mock_responses directory using reliable relative paths.

Types

type MockRoundTripper

type MockRoundTripper struct {
	Response *http.Response // Predefined response to return
	Err      error          // Optional error to return
	// contains filtered or unexported fields
}

MockRoundTripper implements http.RoundTripper for mocking HTTP responses.

func (*MockRoundTripper) RoundTrip

func (m *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction, returning the mock response.

func (*MockRoundTripper) SetRoundTrip

func (m *MockRoundTripper) SetRoundTrip(roundTrip func(*http.Request) (*http.Response, error))

SetRoundTrip sets a custom round trip function for the mock.

Jump to

Keyboard shortcuts

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