Files
ayatori/internal/database/adapter/postgresql/resources_test.go
T
panxiao81 e2016d3727
Verify / test (pull_request) Successful in 9m19s
Verify / lint (pull_request) Successful in 10m19s
Verify / database-integration (pull_request) Successful in 12m12s
feat: 接通 PostgreSQL 角色与数据库创建闭环
2026-09-29 16:04:52 +00:00

36 lines
1.1 KiB
Go

package postgresql
import (
"errors"
"testing"
"git.ddupan.top/panxiao81/ayatori/internal/database/application"
"github.com/jackc/pgx/v5/pgconn"
)
func TestCreationErrorsDoNotExposeServerDetails(t *testing.T) {
for _, test := range []struct {
code string
want error
}{
{"42710", application.ErrResourceConflict},
{"42P04", application.ErrResourceConflict},
{"23505", application.ErrResourceConflict},
{"42501", application.ErrResourceUnavailable},
{"25006", application.ErrResourceUnavailable},
{"57014", application.ErrResourceUncertain},
{"XX000", application.ErrResourceUncertain},
} {
actual := creationError(&pgconn.PgError{Code: test.code, Message: "unsafe SQL and credential detail"})
if !errors.Is(actual, test.want) {
t.Fatalf("SQLSTATE %s 分类错误", test.code)
}
if actual.Error() != test.want.Error() {
t.Fatal("后端错误携带原始响应")
}
}
if !errors.Is(creationError(errors.New("connection lost after send")), application.ErrResourceUncertain) {
t.Fatal("未知网络结果不允许自动重试创建")
}
}