Files
MyGoNavi/internal/app/methods_db_sqlite_test.go
Syngnat 176b100274 🐛 fix(app): 修复品牌图标与 SQLite 查询展示
- 修复 Windows、macOS 与关于页的品牌图标展示及资源裁切问题
- 补齐 SQLite 表记录数与 SELECT 查询结果渲染
- 增加品牌图标和 SQLite 回归测试
2026-07-15 22:53:47 +08:00

91 lines
2.9 KiB
Go

//go:build gonavi_full_drivers || gonavi_sqlite_driver
package app
import (
"path/filepath"
"testing"
"GoNavi-Wails/internal/connection"
)
func TestDBGetTablesIncludesSQLiteRowCounts(t *testing.T) {
app := newSQLAuditTestApp(t)
databasePath := filepath.Join(t.TempDir(), "table-counts.sqlite")
config := connection.ConnectionConfig{
Type: "custom",
Driver: "sqlite",
DSN: databasePath,
Database: databasePath,
}
t.Cleanup(func() { app.DBReleaseConnection(config) })
for _, statement := range []string{
"CREATE TABLE orders (id INTEGER PRIMARY KEY)",
"INSERT INTO orders(id) VALUES (1), (2)",
} {
result := app.DBQueryMulti(config, databasePath, statement, "sqlite-table-counts")
if !result.Success {
t.Fatalf("DBQueryMulti(%q) returned failure: %s", statement, result.Message)
}
}
result := app.DBGetTables(config, databasePath)
if !result.Success {
t.Fatalf("DBGetTables returned failure: %s", result.Message)
}
tables, ok := result.Data.([]map[string]string)
if !ok {
t.Fatalf("DBGetTables data type = %T, want []map[string]string", result.Data)
}
for _, table := range tables {
if table["Table"] == "orders" {
if table["Rows"] != "2" {
t.Fatalf("SQLite table row count = %q, want 2", table["Rows"])
}
return
}
}
t.Fatalf("orders table missing from SQLite table list: %#v", tables)
}
func TestDBQueryMultiReturnsSQLiteRows(t *testing.T) {
app := newSQLAuditTestApp(t)
databasePath := filepath.Join(t.TempDir(), "query-results.sqlite")
config := connection.ConnectionConfig{
Type: "custom",
Driver: "sqlite",
DSN: databasePath,
Database: databasePath,
}
t.Cleanup(func() { app.DBReleaseConnection(config) })
for _, statement := range []string{
"CREATE TABLE orders (id INTEGER PRIMARY KEY, name TEXT)",
"INSERT INTO orders(id, name) VALUES (1, 'SQLite row')",
} {
result := app.DBQueryMulti(config, databasePath, statement, "sqlite-query-results")
if !result.Success {
t.Fatalf("DBQueryMulti(%q) returned failure: %s", statement, result.Message)
}
}
result := app.DBQueryMulti(config, databasePath, "SELECT id, name FROM orders", "sqlite-query-results")
if !result.Success {
t.Fatalf("SQLite SELECT returned failure: %s", result.Message)
}
resultSets, ok := result.Data.([]connection.ResultSetData)
if !ok {
t.Fatalf("SQLite SELECT data type = %T, want []connection.ResultSetData", result.Data)
}
if len(resultSets) != 1 || len(resultSets[0].Rows) != 1 {
t.Fatalf("SQLite SELECT result sets = %#v, want one row", resultSets)
}
if len(resultSets[0].Columns) != 2 || resultSets[0].Columns[0] != "id" || resultSets[0].Columns[1] != "name" {
t.Fatalf("SQLite SELECT columns = %#v, want [id name]", resultSets[0].Columns)
}
if resultSets[0].Rows[0]["id"] != int64(1) || resultSets[0].Rows[0]["name"] != "SQLite row" {
t.Fatalf("SQLite SELECT row = %#v", resultSets[0].Rows[0])
}
}