2026-03-28 11:29:09 -05:00
|
|
|
package sinks
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/config"
|
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-28 13:52:48 -05:00
|
|
|
func TestPostgresFactoryReturnsWorkingFactory(t *testing.T) {
|
|
|
|
|
factory := PostgresFactory(testPostgresSchema())
|
|
|
|
|
if factory == nil {
|
|
|
|
|
t.Fatalf("PostgresFactory() returned nil")
|
2026-03-28 11:29:09 -05:00
|
|
|
}
|
2026-03-28 13:52:48 -05:00
|
|
|
if _, err := factory(config.SinkConfig{}); err == nil {
|
|
|
|
|
t.Fatalf("factory(config) expected parameter validation error")
|
2026-03-28 11:29:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testPostgresSchema() PostgresSchema {
|
|
|
|
|
return PostgresSchema{
|
|
|
|
|
Tables: []PostgresTable{
|
|
|
|
|
{
|
|
|
|
|
Name: "events",
|
|
|
|
|
Columns: []PostgresColumn{
|
|
|
|
|
{Name: "event_id", Type: "TEXT", Nullable: false},
|
|
|
|
|
{Name: "emitted_at", Type: "TIMESTAMPTZ", Nullable: false},
|
|
|
|
|
},
|
|
|
|
|
PrimaryKey: []string{"event_id"},
|
|
|
|
|
PruneColumn: "emitted_at",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
MapEvent: func(_ context.Context, e event.Event) ([]PostgresWrite, error) {
|
|
|
|
|
return []PostgresWrite{
|
|
|
|
|
{
|
|
|
|
|
Table: "events",
|
|
|
|
|
Values: map[string]any{
|
|
|
|
|
"event_id": e.ID,
|
|
|
|
|
"emitted_at": e.EmittedAt,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|