2019-08-11 16:55:18 +02:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-09 01:43:14 +00:00
|
|
|
"github.com/Gleipnir-Technology/jet/internal/testutils"
|
|
|
|
|
. "github.com/Gleipnir-Technology/jet/mysql"
|
|
|
|
|
. "github.com/Gleipnir-Technology/jet/tests/.gentestdata/mysql/dvds/table"
|
2020-05-09 11:00:22 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-11 16:55:18 +02:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLockRead(t *testing.T) {
|
|
|
|
|
query := Customer.LOCK().READ()
|
|
|
|
|
|
|
|
|
|
testutils.AssertStatementSql(t, query, `
|
|
|
|
|
LOCK TABLES dvds.customer READ;
|
|
|
|
|
`)
|
2024-03-07 18:01:31 +01:00
|
|
|
tx, err := db.DB.Begin() // can't prepare LOCK statement
|
2020-05-09 11:00:22 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-07 18:01:31 +01:00
|
|
|
defer func() {
|
|
|
|
|
err := tx.Rollback()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
testutils.AssertExec(t, query, tx)
|
2019-08-11 16:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockWrite(t *testing.T) {
|
|
|
|
|
query := Customer.LOCK().WRITE()
|
|
|
|
|
|
|
|
|
|
testutils.AssertStatementSql(t, query, `
|
|
|
|
|
LOCK TABLES dvds.customer WRITE;
|
|
|
|
|
`)
|
|
|
|
|
|
2024-03-07 18:01:31 +01:00
|
|
|
tx, err := db.DB.Begin() // can't prepare LOCK statement
|
2020-05-09 11:00:22 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-07 18:01:31 +01:00
|
|
|
defer func() {
|
|
|
|
|
err := tx.Rollback()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
testutils.AssertExec(t, query, tx)
|
2019-08-11 16:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnlockTables(t *testing.T) {
|
|
|
|
|
query := UNLOCK_TABLES()
|
|
|
|
|
|
|
|
|
|
testutils.AssertStatementSql(t, query, `
|
|
|
|
|
UNLOCK TABLES;
|
|
|
|
|
`)
|
|
|
|
|
|
2024-03-07 18:01:31 +01:00
|
|
|
tx, err := db.DB.Begin() // can't prepare LOCK statement
|
2020-05-09 11:00:22 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-07 18:01:31 +01:00
|
|
|
defer func() {
|
|
|
|
|
err := tx.Rollback()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
testutils.AssertExec(t, query, tx)
|
2019-08-11 16:55:18 +02:00
|
|
|
}
|