client_link_postgres_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. package service
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  7. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  8. )
  9. // PostgreSQL before 16 rejects a FROM subquery without an alias, so the TUIC
  10. // duplicate-UUID guard must not break client sync for every protocol there.
  11. func TestSyncInboundClientsOnPostgres(t *testing.T) {
  12. db := durablePostgresDB(t)
  13. suffix := time.Now().UnixNano()
  14. inbound := durableTestInbound(nil, fmt.Sprintf("pg-sync-%d", suffix), 20000+int(suffix%20000))
  15. if err := db.Create(inbound).Error; err != nil {
  16. t.Fatalf("create inbound: %v", err)
  17. }
  18. email := fmt.Sprintf("pg-sync-%d@x", suffix)
  19. t.Cleanup(func() {
  20. _ = db.Where("email = ?", email).Delete(&xray.ClientTraffic{}).Error
  21. _ = db.Where("email = ?", email).Delete(&model.ClientRecord{}).Error
  22. _ = db.Delete(&model.Inbound{}, inbound.Id).Error
  23. })
  24. clients := []model.Client{{ID: "8a9c1b2e-1111-4c3d-9e8f-000000000001", Email: email, Enable: true}}
  25. if err := (&ClientService{}).SyncInbound(nil, inbound.Id, clients); err != nil {
  26. t.Fatalf("SyncInbound on PostgreSQL: %v", err)
  27. }
  28. }