chore: initial import
This commit is contained in:
37
internal/database/database_test.go
Normal file
37
internal/database/database_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/company/ai-ops/internal/config"
|
||||
)
|
||||
|
||||
func TestInitAndCloseWithLocalPostgres(t *testing.T) {
|
||||
ports := []int{15432, 5432}
|
||||
var lastErr error
|
||||
for _, port := range ports {
|
||||
lastErr = Init(config.DatabaseConfig{Host: "localhost", Port: port, User: "aiops", Password: "aiops123", DBName: "ai_ops", SSLMode: "disable", PoolSize: 4})
|
||||
if lastErr == nil {
|
||||
break
|
||||
}
|
||||
Close()
|
||||
Pool = nil
|
||||
}
|
||||
if lastErr != nil {
|
||||
t.Skipf("PostgreSQL integration database not available: %v", lastErr)
|
||||
}
|
||||
if Pool == nil {
|
||||
t.Fatal("pool not initialized")
|
||||
}
|
||||
Close()
|
||||
Pool = nil
|
||||
}
|
||||
|
||||
func TestInitReturnsErrorForInvalidConfig(t *testing.T) {
|
||||
if err := Init(config.DatabaseConfig{Host: "::::bad-host::::", Port: 1, User: "u", Password: "p", DBName: "d", SSLMode: "disable", PoolSize: 1}); err == nil {
|
||||
Close()
|
||||
Pool = nil
|
||||
t.Fatal("expected invalid db config error")
|
||||
}
|
||||
Pool = nil
|
||||
}
|
||||
Reference in New Issue
Block a user