testing

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testing provides test utilities for NestGo applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockProvider

func MockProvider[T any](mock T) di.Provider

MockProvider creates a mock provider for testing.

Types

type TestApp

type TestApp struct {
	App       *core.NestGoApp
	Container *di.Container
	Server    *httptest.Server
}

TestApp provides a test harness for NestGo applications.

func NewTestApp

func NewTestApp(mods ...common.Module) *TestApp

NewTestApp creates a new test application.

func (*TestApp) Close

func (t *TestApp) Close()

Close shuts down the test server.

func (*TestApp) OverrideProvider

func (t *TestApp) OverrideProvider(value any) *TestApp

OverrideProvider replaces a provider in the DI container (for mocking).

func (*TestApp) Start

func (t *TestApp) Start() *TestApp

Start starts the test server.

func (*TestApp) URL

func (t *TestApp) URL() string

URL returns the test server URL.

type TestRequest

type TestRequest struct {
	// contains filtered or unexported fields
}

TestRequest builds and sends test HTTP requests.

func DELETE

func DELETE(baseURL, path string) *TestRequest

DELETE creates a DELETE test request.

func GET

func GET(baseURL, path string) *TestRequest

GET creates a GET test request.

func POST

func POST(baseURL, path string, body any) *TestRequest

POST creates a POST test request.

func PUT

func PUT(baseURL, path string, body any) *TestRequest

PUT creates a PUT test request.

func (*TestRequest) Send

func (r *TestRequest) Send() (*TestResponse, error)

Send sends the request and returns the response.

func (*TestRequest) WithAuth

func (r *TestRequest) WithAuth(token string) *TestRequest

WithAuth adds a bearer token.

func (*TestRequest) WithHeader

func (r *TestRequest) WithHeader(key, value string) *TestRequest

WithHeader adds a header.

type TestResponse

type TestResponse struct {
	*http.Response
}

TestResponse wraps an HTTP response with convenience methods.

func (*TestResponse) BodyString

func (r *TestResponse) BodyString() string

BodyString returns the response body as a string.

func (*TestResponse) IsCreated

func (r *TestResponse) IsCreated() bool

IsCreated returns true if status is 201.

func (*TestResponse) IsNotFound

func (r *TestResponse) IsNotFound() bool

IsNotFound returns true if status is 404.

func (*TestResponse) IsOK

func (r *TestResponse) IsOK() bool

IsOK returns true if status is 200.

func (*TestResponse) JSON

func (r *TestResponse) JSON(v any) error

JSON decodes the response body as JSON.

Jump to

Keyboard shortcuts

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