helpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, rr *httptest.ResponseRecorder, expectedStatus int, expectedBody interface{})

AssertJSONResponse asserts that the response has the expected status code and JSON body

func CleanupTestEnv

func CleanupTestEnv(t *testing.T)

CleanupTestEnv cleans up test environment variables

func CleanupTestUsers

func CleanupTestUsers(t *testing.T)

CleanupTestUsers removes all test users from the main database This should be called at the start and end of integration tests to ensure clean state

func CreateTestArticle

func CreateTestArticle(t *testing.T, db database.Database, feedID int, title, url string) *database.Article

CreateTestArticle creates a test article in the database

func CreateTestDB

func CreateTestDB(t *testing.T) database.Database

CreateTestDB creates an in-memory SQLite database for testing

func CreateTestDatastoreDB

func CreateTestDatastoreDB(t *testing.T) database.Database

CreateTestDatastoreDB creates a Datastore database for testing This requires the Datastore emulator to be running

func CreateTestFeed

func CreateTestFeed(t *testing.T, db database.Database, title, url, description string) *database.Feed

CreateTestFeed creates a test feed in the database

func CreateTestUser

func CreateTestUser(t *testing.T, db database.Database, googleID, email, name string) *database.User

CreateTestUser creates a test user in the database

func CreateUnauthenticatedRequest

func CreateUnauthenticatedRequest(t *testing.T, method, url string, body interface{}) *http.Request

CreateUnauthenticatedRequest creates an HTTP request without authentication

func NewMockFeedServer

func NewMockFeedServer(t *testing.T, feedXML string) *httptest.Server

NewMockFeedServer creates a mock HTTP server that serves RSS/Atom feed content Returns the server and its URL. The caller must call server.Close() when done.

func NewMockFeedServerWithStatus

func NewMockFeedServerWithStatus(t *testing.T, statusCode int, body string) *httptest.Server

NewMockFeedServerWithStatus creates a mock HTTP server that returns a specific status code

func NewMockMultiFeedServer

func NewMockMultiFeedServer(t *testing.T, feeds map[string]string) *httptest.Server

NewMockMultiFeedServer creates a mock HTTP server that can serve different feeds based on the path

func SetupTestEnv

func SetupTestEnv(t *testing.T)

SetupTestEnv sets up environment variables for testing

Types

type MockHTTPClient

type MockHTTPClient struct {
	Server *httptest.Server
}

MockHTTPClient wraps an httptest.Server to provide an HTTP client that redirects all requests to the mock server

func NewMockHTTPClient

func NewMockHTTPClient(server *httptest.Server) *MockHTTPClient

NewMockHTTPClient creates a mock HTTP client from an httptest.Server

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do implements the HTTPClient interface by executing the request

type TestServer

type TestServer struct {
	Router         *gin.Engine
	AuthService    *auth.AuthService
	SessionManager *auth.SessionManager
	CSRFManager    *auth.CSRFManager
	FeedHandler    *handlers.FeedHandler
	AuthHandler    *handlers.AuthHandler
	DB             database.Database
}

TestServer wraps the test server with authentication helpers

func SetupTestServer

func SetupTestServer(t *testing.T) *TestServer

SetupTestServer creates a test server with all dependencies

func (*TestServer) CreateAuthenticatedRequest

func (ts *TestServer) CreateAuthenticatedRequest(t *testing.T, method, url string, body interface{}, user *database.User) *http.Request

CreateAuthenticatedRequest creates an HTTP request with authentication and CSRF token

func (*TestServer) ExecuteRequest

func (ts *TestServer) ExecuteRequest(req *http.Request) *httptest.ResponseRecorder

ExecuteRequest executes an HTTP request and returns the response

Jump to

Keyboard shortcuts

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