CI / changes (push) Successful in 13s
CI / commitlint (push) Has been skipped
CI / openapi (push) Has been skipped
CI / web (push) Has been skipped
CI / go (push) Successful in 1m6s
CI / bird2 (push) Successful in 18s
CI / release (push) Successful in 3m57s
Refactored the SQL queries in the Postgres repository for listing and retrieving firewall clients by introducing a constant for the selected columns. This change improves code readability and maintainability by reducing duplication in the query definitions. No functional changes were made to the data retrieval process.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"evobgp/internal/authkey"
|
|
"evobgp/internal/db"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
func TestPostgresFirewallClientCreateAndGetIntegration(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, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tenant, _, _, _, _ := pg.DemoIDs()
|
|
if tenant == "" {
|
|
t.Fatal("demo tenant required")
|
|
}
|
|
tok := "evobgp_fw_pgtest_" + t.Name()
|
|
hash := authkey.HashToken(tok)
|
|
client, err := pg.CreateFirewallClient(tenant, &store.FirewallClientCreate{
|
|
Name: "pg-firewall-test",
|
|
Hostname: "test.local",
|
|
TokenPrefix: tok[:12],
|
|
TokenHash: hash,
|
|
ClientVersion: "test/1",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("create: %v", err)
|
|
}
|
|
got, err := pg.GetFirewallClient(tenant, client.ID)
|
|
if err != nil {
|
|
t.Fatalf("get: %v", err)
|
|
}
|
|
if got.Name != "pg-firewall-test" || got.Status != "pending" {
|
|
t.Fatalf("got %+v", got)
|
|
}
|
|
_ = pg.DeleteFirewallClient(tenant, client.ID)
|
|
}
|