CI / changes (push) Successful in 7s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 23s
CI / web (push) Failing after 34s
CI / go (push) Failing after 41s
CI / bird2 (push) Has been skipped
CI / release (push) Has been skipped
Уточнение godoc ExtractCIDRs; тесты repository (interface + optional integration). Co-authored-by: Cursor <[email protected]>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"evobgp/internal/db"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
func TestPostgresImplementsBackend(t *testing.T) {
|
|
var _ store.Backend = (*Postgres)(nil)
|
|
}
|
|
|
|
func TestPostgresPingIntegration(t *testing.T) {
|
|
dsn := os.Getenv("EVOBGP_TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("EVOBGP_TEST_DATABASE_URL not set")
|
|
}
|
|
ctx := context.Background()
|
|
pool, err := db.OpenPostgresPool(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer pool.Close()
|
|
pg, err := NewPostgres(ctx, pool, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := pg.Ping(ctx); err != nil {
|
|
t.Fatalf("ping: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPostgresModuleCRUDIntegration(t *testing.T) {
|
|
dsn := os.Getenv("EVOBGP_TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("EVOBGP_TEST_DATABASE_URL not set")
|
|
}
|
|
ctx := context.Background()
|
|
pool, err := db.OpenPostgresPool(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer pool.Close()
|
|
pg, err := NewPostgres(ctx, pool, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tenant := "01TESTTENANT00000000000001"
|
|
mod, err := pg.CreateModule(tenant, &store.Module{
|
|
Name: "audit-test",
|
|
Type: "IP_RANGES",
|
|
Enabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := pg.GetModule(tenant, mod.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Name != "audit-test" {
|
|
t.Fatalf("name: got %q", got.Name)
|
|
}
|
|
if err := pg.SoftDeleteModule(tenant, mod.ID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|