package migrate import ( "strings" "testing" ) func TestSqlite3Dialect(t *testing.T) { sl3 := Sqlite3() t.Run("CreateTable", func(t *testing.T) { sql := sl3.CreateTable("dbversion") if !strings.Contains(sql, "INTEGER PRIMARY KEY AUTOINCREMENT") { t.Errorf("Expected INTEGER PRIMARY KEY AUTOINCREMENT, got: %s", sql) } if !strings.Contains(sql, `"dbversion"`) { t.Errorf("Expected quoted table name, got: %s", sql) } }) t.Run("TableExists", func(t *testing.T) { sql := sl3.TableExists("dbversion") if !strings.Contains(sql, `"dbversion"`) { t.Errorf("Expected quoted table name, got: %s", sql) } if !strings.Contains(sql, "SELECT *") { t.Errorf("Expected SELECT *, got: %s", sql) } }) t.Run("CheckVersion", func(t *testing.T) { sql := sl3.CheckVersion("dbversion") if !strings.Contains(sql, "ORDER BY id DESC") { t.Errorf("Expected ORDER BY id DESC, got: %s", sql) } if !strings.Contains(sql, "LIMIT 0, 1") { t.Errorf("Expected LIMIT 0, 1, got: %s", sql) } }) t.Run("InsertVersion", func(t *testing.T) { sql := sl3.InsertVersion("dbversion") // SQLite uses ? placeholders if !strings.Contains(sql, "VALUES (?,?)") { t.Errorf("Expected SQLite placeholders (?,?), got: %s", sql) } if !strings.Contains(sql, `"dbversion"`) { t.Errorf("Expected quoted table name, got: %s", sql) } }) t.Run("QuoteIdentifier", func(t *testing.T) { sl3 := sqlite3{} // Test normal identifier quoted := sl3.quoteIdentifier("tablename") if quoted != `"tablename"` { t.Errorf("Expected quoted identifier, got: %s", quoted) } // Test identifier with quotes (SQL injection attempt) quoted = sl3.quoteIdentifier(`table"; DROP TABLE users; --`) if !strings.Contains(quoted, `""`) { t.Errorf("Expected escaped quotes, got: %s", quoted) } }) }