Documentation
¶
Index ¶
- func AssertJSONContains(t *testing.T, jsonBody []byte, expectedFields map[string]interface{})
- func CreateRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
- func CreateTestContext() (*gin.Context, *httptest.ResponseRecorder)
- func CreateTestOrganization(tenantID string) map[string]interface{}
- func CreateTestUser(tenantID string) map[string]interface{}
- func ParseJSONResponse(t *testing.T, resp *http.Response) map[string]interface{}
- func SetupTestRouter() *gin.Engine
- type HTTPTestHelper
- func (h *HTTPTestHelper) AssertErrorResponse(t *testing.T, resp *http.Response, expectedStatus int, ...)
- func (h *HTTPTestHelper) AssertHealthCheck(t *testing.T, url string)
- func (h *HTTPTestHelper) AssertResponse(t *testing.T, resp *http.Response, expected *TestResponse)
- func (h *HTTPTestHelper) DELETE(t *testing.T, url string) *http.Response
- func (h *HTTPTestHelper) GET(t *testing.T, url string, queryParams map[string]string) *http.Response
- func (h *HTTPTestHelper) GetJSON(t *testing.T, url string, expectedResponse interface{}, expectedStatus int)
- func (h *HTTPTestHelper) GetServerURL() string
- func (h *HTTPTestHelper) MakeRequest(t *testing.T, req *TestRequest) *http.Response
- func (h *HTTPTestHelper) PATCH(t *testing.T, url string, body interface{}) *http.Response
- func (h *HTTPTestHelper) POST(t *testing.T, url string, body interface{}) *http.Response
- func (h *HTTPTestHelper) PUT(t *testing.T, url string, body interface{}) *http.Response
- func (h *HTTPTestHelper) PostJSON(t *testing.T, url string, requestBody, expectedResponse interface{}, ...)
- func (h *HTTPTestHelper) StartServer()
- func (h *HTTPTestHelper) StopServer()
- func (h *HTTPTestHelper) WithTenantID(tenantID string) *HTTPTestHelper
- func (h *HTTPTestHelper) WithUserID(userID string) *HTTPTestHelper
- type MockResponseWriter
- func (m *MockResponseWriter) GetBody() string
- func (m *MockResponseWriter) GetHeaders() http.Header
- func (m *MockResponseWriter) GetStatusCode() int
- func (m *MockResponseWriter) Header() http.Header
- func (m *MockResponseWriter) Write(data []byte) (int, error)
- func (m *MockResponseWriter) WriteHeader(statusCode int)
- type TestAuthHelper
- type TestRequest
- type TestResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertJSONContains ¶
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 ¶
CreateTestOrganization crea una organización de prueba
func CreateTestUser ¶
CreateTestUser crea un usuario de prueba con datos básicos
func ParseJSONResponse ¶
ParseJSONResponse parses JSON response into a map
func SetupTestRouter ¶
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) 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) 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) 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