feat(store): pgx pool and endpoints CRUD

This commit is contained in:
2026-07-01 16:50:45 +07:00
parent edda3dc21f
commit 420358b558
5 changed files with 149 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
package store
import (
"context"
"os"
"testing"
)
func testStore(t *testing.T) *Store {
dsn := os.Getenv("TEST_DATABASE_URL")
if dsn == "" {
t.Skip("TEST_DATABASE_URL not set")
}
s, err := New(context.Background(), dsn)
if err != nil {
t.Fatalf("New: %v", err)
}
t.Cleanup(func() {
s.Pool.Exec(context.Background(),
`TRUNCATE endpoints, tasks, accounts, runs, migrated_messages RESTART IDENTITY CASCADE`)
s.Pool.Close()
})
return s
}
func TestCreateAndGetEndpoint(t *testing.T) {
s := testStore(t)
ctx := context.Background()
id, err := s.CreateEndpoint(ctx, Endpoint{RoleLabel: "src", Host: "imap.a.com", Port: 993, TLSMode: "ssl"})
if err != nil {
t.Fatalf("create: %v", err)
}
got, err := s.GetEndpoint(ctx, id)
if err != nil {
t.Fatalf("get: %v", err)
}
if got.Host != "imap.a.com" || got.Port != 993 {
t.Fatalf("got %+v", got)
}
}