Skip to content

Commit e2ba6eb

Browse files
committed
Config: Drop unreachable DatabaseDriverName switch cases photoprism#5588
1 parent 18214b2 commit e2ba6eb

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

internal/config/config_db.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ func (c *Config) DatabaseDriver() string {
5252
return c.options.DatabaseDriver
5353
}
5454

55-
// DatabaseDriverName returns the formatted database driver name.
55+
// DatabaseDriverName returns the formatted database driver name. Input is
56+
// always canonical after DatabaseDriver(); the default arm is defensive.
5657
func (c *Config) DatabaseDriverName() string {
5758
switch c.DatabaseDriver() {
58-
case dsn.DriverMySQL, dsn.DriverMariaDB:
59+
case dsn.DriverMySQL:
5960
return "MariaDB"
60-
case dsn.DriverSQLite3, "sqlite", "test", "file", "":
61+
case dsn.DriverSQLite3:
6162
return "SQLite"
62-
case "tidb":
63-
return "TiDB"
6463
default:
6564
return "unsupported database"
6665
}

internal/config/config_db_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,38 @@ func TestConfig_DatabaseDriver(t *testing.T) {
4444
}
4545

4646
func TestConfig_DatabaseDriverName(t *testing.T) {
47-
c := NewConfig(CliTestContext())
48-
resetDatabaseOptions(c)
49-
driver := c.DatabaseDriverName()
50-
assert.Equal(t, "SQLite", driver)
47+
t.Run("DefaultsToSQLite", func(t *testing.T) {
48+
c := NewConfig(CliTestContext())
49+
resetDatabaseOptions(c)
50+
assert.Equal(t, "SQLite", c.DatabaseDriverName())
51+
})
52+
t.Run("MySQLReportsAsMariaDB", func(t *testing.T) {
53+
c := NewConfig(CliTestContext())
54+
resetDatabaseOptions(c)
55+
c.options.DatabaseDriver = dsn.DriverMySQL
56+
assert.Equal(t, "MariaDB", c.DatabaseDriverName())
57+
})
58+
t.Run("MariaDBAliasReportsAsMariaDB", func(t *testing.T) {
59+
// "mariadb" collapses onto DriverMySQL in ParseDriver; format stays "MariaDB".
60+
c := NewConfig(CliTestContext())
61+
resetDatabaseOptions(c)
62+
c.options.DatabaseDriver = dsn.DriverMariaDB
63+
assert.Equal(t, "MariaDB", c.DatabaseDriverName())
64+
})
65+
t.Run("DeprecatedTiDBReportsAsSQLite", func(t *testing.T) {
66+
// DatabaseDriver() warns and rewrites "tidb" to SQLite3 before this runs.
67+
c := NewConfig(CliTestContext())
68+
resetDatabaseOptions(c)
69+
c.options.DatabaseDriver = "tidb"
70+
assert.Equal(t, "SQLite", c.DatabaseDriverName())
71+
})
72+
t.Run("UnknownDriverReportsAsSQLite", func(t *testing.T) {
73+
// DatabaseDriver() coerces unknown drivers to SQLite3 before this runs.
74+
c := NewConfig(CliTestContext())
75+
resetDatabaseOptions(c)
76+
c.options.DatabaseDriver = "oracle"
77+
assert.Equal(t, "SQLite", c.DatabaseDriverName())
78+
})
5179
}
5280

5381
func TestConfig_DatabaseVersion(t *testing.T) {

0 commit comments

Comments
 (0)