Files
DiunDashboard/pkg/diunwebhook/export_test.go
Jean-Luc Makiola 95b64b4d54 feat(03-01): add pgx/v5, PostgreSQL migrations, rename RunMigrations to RunSQLiteMigrations
- Add github.com/jackc/pgx/v5 v5.9.1 dependency
- Add golang-migrate pgx/v5 driver
- Create migrations/postgres/0001_initial_schema.up.sql with SERIAL PRIMARY KEY
- Create migrations/postgres/0001_initial_schema.down.sql
- Rename RunMigrations to RunSQLiteMigrations in migrate.go
- Add RunPostgresMigrations with pgxmigrate driver and 'pgx5' name
- Update export_test.go to use RunSQLiteMigrations (go vet compliance)
2026-03-24 09:08:53 +01:00

47 lines
1.3 KiB
Go

package diunwebhook
import "database/sql"
// NewTestServer constructs a Server with a fresh in-memory SQLite database.
// Each call returns an isolated server -- tests do not share state.
func NewTestServer() (*Server, error) {
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
return nil, err
}
if err := RunSQLiteMigrations(db); err != nil {
return nil, err
}
store := NewSQLiteStore(db)
return NewServer(store, ""), nil
}
// NewTestServerWithSecret constructs a Server with webhook authentication enabled.
func NewTestServerWithSecret(secret string) (*Server, error) {
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
return nil, err
}
if err := RunSQLiteMigrations(db); err != nil {
return nil, err
}
store := NewSQLiteStore(db)
return NewServer(store, secret), nil
}
// TestUpsertEvent calls UpsertEvent on the server's store (for test setup).
func (s *Server) TestUpsertEvent(event DiunEvent) error {
return s.store.UpsertEvent(event)
}
// TestGetUpdates calls GetUpdates on the server's store (for test assertions).
func (s *Server) TestGetUpdates() (map[string]UpdateEntry, error) {
return s.store.GetUpdates()
}
// TestGetUpdatesMap is a convenience wrapper that returns the map without error.
func (s *Server) TestGetUpdatesMap() map[string]UpdateEntry {
m, _ := s.store.GetUpdates()
return m
}