/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
pkg/dsn/driver_test.go
57 строк
2 KB
Michael Mayer
Config: Refactor database driver parsing and detection #47 #4831
24 май 2026, 13:24
24 май 2026, 13:24
8a28f60
Код
Авторство
О чём код?
package dsn import ( "testing" "github.com/stretchr/testify/assert" ) func TestParseDriver(t *testing.T) { t.Run("Empty", func(t *testing.T) { // Empty defaults to SQLite, matching the legacy config switch. assert.Equal(t, DriverNone, ParseDriver("")) assert.Equal(t, DriverNone, ParseDriver(" ")) }) t.Run("Auto", func(t *testing.T) { // Empty defaults to SQLite, matching the legacy config switch. assert.Equal(t, DriverAuto, ParseDriver("auto")) assert.Equal(t, DriverAuto, ParseDriver(" AUTO ")) }) t.Run("MySQL", func(t *testing.T) { assert.Equal(t, DriverMySQL, ParseDriver("mysql")) assert.Equal(t, DriverMySQL, ParseDriver("MySQL")) assert.Equal(t, DriverMySQL, ParseDriver(" mysql ")) }) t.Run("MariaDB", func(t *testing.T) { // MariaDB and MySQL share a wire protocol and GORM dialect, so the // parser collapses both onto DriverMySQL. assert.Equal(t, DriverMySQL, ParseDriver("mariadb")) assert.Equal(t, DriverMySQL, ParseDriver("MariaDB")) }) t.Run("Postgres", func(t *testing.T) { assert.Equal(t, DriverPostgres, ParseDriver("postgres")) // URI-style DSNs spell the driver "postgresql"; accept it as a Postgres alias. assert.Equal(t, DriverPostgres, ParseDriver("postgresql")) assert.Equal(t, DriverPostgres, ParseDriver("PostgreSQL")) }) t.Run("SQLite3", func(t *testing.T) { assert.Equal(t, DriverSQLite3, ParseDriver("sqlite3")) assert.Equal(t, DriverSQLite3, ParseDriver("SQLite3")) }) t.Run("SQLiteAliases", func(t *testing.T) { // Aliases that have historically resolved to the SQLite driver. assert.Equal(t, DriverSQLite3, ParseDriver("sqlite")) assert.Equal(t, DriverSQLite3, ParseDriver("test")) assert.Equal(t, DriverSQLite3, ParseDriver("file")) }) t.Run("TiDB", func(t *testing.T) { // Recognized so callers can treat it as deprecated; not a supported driver. assert.Equal(t, DriverTiDB, ParseDriver("tidb")) assert.Equal(t, DriverTiDB, ParseDriver("TiDB")) }) t.Run("Unknown", func(t *testing.T) { // Unknown inputs return an empty string so the caller's `default` arm fires. assert.Equal(t, "", ParseDriver("oracle")) assert.Equal(t, "", ParseDriver("garbage")) }) }