httptest

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSONContains

func AssertJSONContains(t *testing.T, jsonBody []byte, expectedFields map[string]interface{})

AssertJSONContains verifica que el JSON contenga los campos esperados

func CreateRequestWithContext

func CreateRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)

CreateRequestWithContext crea una request HTTP con contexto personalizado

func CreateTestContext

func CreateTestContext() (*gin.Context, *httptest.ResponseRecorder)

CreateTestContext crea un contexto Gin para pruebas unitarias

func CreateTestOrganization

func CreateTestOrganization(tenantID string) map[string]interface{}

CreateTestOrganization crea una organización de prueba

func CreateTestUser

func CreateTestUser(tenantID string) map[string]interface{}

CreateTestUser crea un usuario de prueba con datos básicos

func ParseJSONResponse

func ParseJSONResponse(t *testing.T, resp *http.Response) map[string]interface{}

ParseJSONResponse parses JSON response into a map

func SetupTestRouter

func SetupTestRouter() *gin.Engine

SetupTestRouter configura un router Gin para pruebas

Types

type HTTPTestHelper

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

HTTPTestHelper ayuda con las pruebas HTTP

func NewHTTPTestHelper

func NewHTTPTestHelper(router *gin.Engine, tenantID, userID string) *HTTPTestHelper

NewHTTPTestHelper crea un nuevo helper HTTP

func (*HTTPTestHelper) AssertErrorResponse

func (h *HTTPTestHelper) AssertErrorResponse(t *testing.T, resp *http.Response, expectedStatus int, expectedErrorCode string)

AssertErrorResponse verifica que la respuesta sea un error con el código esperado

func (*HTTPTestHelper) AssertHealthCheck

func (h *HTTPTestHelper) AssertHealthCheck(t *testing.T, url string)

AssertHealthCheck verifica que el endpoint de health check funcione

func (*HTTPTestHelper) AssertResponse

func (h *HTTPTestHelper) AssertResponse(t *testing.T, resp *http.Response, expected *TestResponse)

AssertResponse verifica que la respuesta coincida con las expectativas

func (*HTTPTestHelper) DELETE

func (h *HTTPTestHelper) DELETE(t *testing.T, url string) *http.Response

DELETE realiza una petición DELETE

func (*HTTPTestHelper) GET

func (h *HTTPTestHelper) GET(t *testing.T, url string, queryParams map[string]string) *http.Response

GET realiza una petición GET

func (*HTTPTestHelper) GetJSON

func (h *HTTPTestHelper) GetJSON(t *testing.T, url string, expectedResponse interface{}, expectedStatus int)

GetJSON realiza una petición GET y verifica la respuesta JSON

func (*HTTPTestHelper) GetServerURL

func (h *HTTPTestHelper) GetServerURL() string

GetServerURL retorna la URL del servidor de prueba

func (*HTTPTestHelper) MakeRequest

func (h *HTTPTestHelper) MakeRequest(t *testing.T, req *TestRequest) *http.Response

MakeRequest realiza una petición HTTP y retorna la respuesta

func (*HTTPTestHelper) PATCH

func (h *HTTPTestHelper) PATCH(t *testing.T, url string, body interface{}) *http.Response

PATCH realiza una petición PATCH

func (*HTTPTestHelper) POST

func (h *HTTPTestHelper) POST(t *testing.T, url string, body interface{}) *http.Response

POST realiza una petición POST

func (*HTTPTestHelper) PUT

func (h *HTTPTestHelper) PUT(t *testing.T, url string, body interface{}) *http.Response

PUT realiza una petición PUT

func (*HTTPTestHelper) PostJSON

func (h *HTTPTestHelper) PostJSON(t *testing.T, url string, requestBody, expectedResponse interface{}, expectedStatus int)

PostJSON realiza una petición POST con JSON y verifica la respuesta

func (*HTTPTestHelper) StartServer

func (h *HTTPTestHelper) StartServer()

StartServer inicia el servidor HTTP de prueba

func (*HTTPTestHelper) StopServer

func (h *HTTPTestHelper) StopServer()

StopServer detiene el servidor HTTP de prueba

func (*HTTPTestHelper) WithTenantID

func (h *HTTPTestHelper) WithTenantID(tenantID string) *HTTPTestHelper

WithTenantID configura el tenant ID para las siguientes peticiones

func (*HTTPTestHelper) WithUserID

func (h *HTTPTestHelper) WithUserID(userID string) *HTTPTestHelper

WithUserID configura el user ID para las siguientes peticiones

type MockResponseWriter

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

MockResponseWriter implementa http.ResponseWriter para pruebas

func NewMockResponseWriter

func NewMockResponseWriter() *MockResponseWriter

NewMockResponseWriter crea un nuevo MockResponseWriter

func (*MockResponseWriter) GetBody

func (m *MockResponseWriter) GetBody() string

func (*MockResponseWriter) GetHeaders

func (m *MockResponseWriter) GetHeaders() http.Header

func (*MockResponseWriter) GetStatusCode

func (m *MockResponseWriter) GetStatusCode() int

func (*MockResponseWriter) Header

func (m *MockResponseWriter) Header() http.Header

func (*MockResponseWriter) Write

func (m *MockResponseWriter) Write(data []byte) (int, error)

func (*MockResponseWriter) WriteHeader

func (m *MockResponseWriter) WriteHeader(statusCode int)

type TestAuthHelper

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

TestAuthHelper ayuda con la autenticación en pruebas

func NewTestAuthHelper

func NewTestAuthHelper(tenantID, userID string) *TestAuthHelper

NewTestAuthHelper crea un nuevo helper de autenticación

func (*TestAuthHelper) CreateJWTToken

func (h *TestAuthHelper) CreateJWTToken() string

CreateJWTToken crea un token JWT de prueba (mock)

func (*TestAuthHelper) GetAuthHeaders

func (h *TestAuthHelper) GetAuthHeaders() map[string]string

GetAuthHeaders retorna headers de autenticación para pruebas

type TestRequest

type TestRequest struct {
	Method      string
	URL         string
	Body        interface{}
	Headers     map[string]string
	QueryParams map[string]string
	TenantID    string
	UserID      string
}

TestRequest representa una petición HTTP de prueba

type TestResponse

type TestResponse struct {
	StatusCode  int
	Body        interface{}
	Headers     map[string]string
	BodyPartial interface{} // Para verificaciones parciales del body
}

TestResponse representa una respuesta HTTP esperada

Jump to

Keyboard shortcuts

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