@@ -16,7 +16,48 @@ import (
1616 "time"
1717)
1818
19- func TestSetMysqlSessionVars (t * testing.T ) {
19+ func TestDatabaseUtils (t * testing.T ) {
20+ t .Parallel ()
21+
22+ ctx := context .Background ()
23+ db := GetTestDB (ctx , t , "ICINGAGOLIBRARY" )
24+
25+ t .Run ("SetMySQLSessionVars" , func (t * testing.T ) {
26+ t .Parallel ()
27+ if db .DriverName () != MySQL {
28+ t .Skipf ("skipping set session vars test for %q driver" , db .DriverName ())
29+ }
30+
31+ setMysqlSessionVars (ctx , db , t )
32+ })
33+
34+ t .Run ("InsertObtainID" , func (t * testing.T ) {
35+ t .Parallel ()
36+
37+ defer func () {
38+ _ , err := db .ExecContext (ctx , "DROP TABLE IF EXISTS igl_test_insert_obtain" )
39+ assert .NoError (t , err , "dropping test database table should not fail" )
40+ }()
41+
42+ var err error
43+ if db .DriverName () == PostgreSQL {
44+ _ , err = db .ExecContext (ctx , "CREATE TABLE igl_test_insert_obtain (id SERIAL PRIMARY KEY, name VARCHAR(255))" )
45+ } else {
46+ _ , err = db .ExecContext (ctx , "CREATE TABLE igl_test_insert_obtain (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))" )
47+ }
48+ require .NoError (t , err , "creating test database table should not fail" )
49+
50+ id , err := InsertObtainID (ctx , db , "INSERT INTO igl_test_insert_obtain (name) VALUES (:name)" , map [string ]any {"name" : "test1" })
51+ require .NoError (t , err , "inserting new row into test database table should not fail" )
52+ assert .Equal (t , id , int64 (1 ))
53+
54+ id , err = InsertObtainID (ctx , db , "INSERT INTO igl_test_insert_obtain (name) VALUES (:name)" , map [string ]any {"name" : "test2" })
55+ require .NoError (t , err , "inserting new row into test database table should not fail" )
56+ assert .Equal (t , id , int64 (2 ))
57+ })
58+ }
59+
60+ func setMysqlSessionVars (ctx context.Context , db * DB , t * testing.T ) {
2061 vars := map [string ][]struct {
2162 name string
2263 value string
@@ -45,14 +86,10 @@ func TestSetMysqlSessionVars(t *testing.T) {
4586 },
4687 }
4788
48- ctx := context .Background ()
49- db := GetTestDB (ctx , t , "ICINGAGOLIBRARY" )
50- if db .DriverName () != MySQL {
51- t .Skipf ("skipping set session vars test for %q driver" , db .DriverName ())
52- }
53-
5489 for name , vs := range vars {
5590 t .Run (name , func (t * testing.T ) {
91+ t .Parallel ()
92+
5693 for _ , v := range vs {
5794 conn , err := db .DB .Conn (ctx )
5895 require .NoError (t , err , "connecting to MySQL/MariaDB database should not fail" )
0 commit comments