Skip to content

Commit 9c1208b

Browse files
committed
Moved tests
1 parent f2d382f commit 9c1208b

File tree

4 files changed

+106
-107
lines changed

4 files changed

+106
-107
lines changed

tests/connection_test.go

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -71,80 +71,6 @@ func TestWithSingleConnection(t *testing.T) {
7171
}
7272
}
7373

74-
func TestTransactionCommit(t *testing.T) {
75-
// Create test table
76-
type TestTxTable struct {
77-
ID uint `gorm:"primaryKey"`
78-
Name string `gorm:"size:100;column:name"`
79-
}
80-
81-
err := DB.AutoMigrate(&TestTxTable{})
82-
if err != nil {
83-
t.Fatalf("Failed to migrate test table: %v", err)
84-
}
85-
defer DB.Migrator().DropTable(&TestTxTable{})
86-
87-
tx := DB.Begin()
88-
if tx.Error != nil {
89-
t.Fatalf("Failed to begin transaction: %v", tx.Error)
90-
}
91-
92-
record := TestTxTable{Name: "test_commit"}
93-
if err := tx.Create(&record).Error; err != nil {
94-
t.Errorf("Failed to create record in transaction: %v", err)
95-
}
96-
97-
if err := tx.Commit().Error; err != nil {
98-
t.Errorf("Failed to commit transaction: %v", err)
99-
}
100-
101-
// Verify record exists using quoted column name
102-
var count int64
103-
if err := DB.Model(&TestTxTable{}).Where("\"name\" = ?", "test_commit").Count(&count).Error; err != nil {
104-
t.Errorf("Failed to count records: %v", err)
105-
}
106-
if count != 1 {
107-
t.Errorf("Expected 1 record after commit, got %d", count)
108-
}
109-
}
110-
111-
func TestTransactionRollback(t *testing.T) {
112-
// Create test table
113-
type TestTxTable struct {
114-
ID uint `gorm:"primaryKey"`
115-
Name string `gorm:"size:100;column:name"`
116-
}
117-
118-
err := DB.AutoMigrate(&TestTxTable{})
119-
if err != nil {
120-
t.Fatalf("Failed to migrate test table: %v", err)
121-
}
122-
defer DB.Migrator().DropTable(&TestTxTable{})
123-
124-
tx := DB.Begin()
125-
if tx.Error != nil {
126-
t.Fatalf("Failed to begin transaction: %v", tx.Error)
127-
}
128-
129-
record := TestTxTable{Name: "test_rollback"}
130-
if err := tx.Create(&record).Error; err != nil {
131-
t.Errorf("Failed to create record in transaction: %v", err)
132-
}
133-
134-
if err := tx.Rollback().Error; err != nil {
135-
t.Errorf("Failed to rollback transaction: %v", err)
136-
}
137-
138-
// Verify record doesn't exist using quoted column name
139-
var count int64
140-
if err := DB.Model(&TestTxTable{}).Where("\"name\" = ?", "test_rollback").Count(&count).Error; err != nil {
141-
t.Errorf("Failed to count records: %v", err)
142-
}
143-
if count != 0 {
144-
t.Errorf("Expected 0 records after rollback, got %d", count)
145-
}
146-
}
147-
14874
func TestConnectionAfterError(t *testing.T) {
14975
// Execute an invalid query
15076
err := DB.Exec("SELECT invalid_column FROM dual").Error
@@ -281,38 +207,6 @@ func TestContextTimeout(t *testing.T) {
281207
}
282208
}
283209

284-
func TestLargeResultSet(t *testing.T) {
285-
var results []struct {
286-
RowNum int `gorm:"column:ROW_NUM"`
287-
Value string `gorm:"column:VALUE"`
288-
}
289-
290-
query := `
291-
SELECT LEVEL as row_num, 'row_' || LEVEL as value
292-
FROM dual
293-
CONNECT BY LEVEL <= 1000
294-
`
295-
296-
err := DB.Raw(query).Scan(&results).Error
297-
if err != nil {
298-
t.Errorf("Failed to execute large result set query: %v", err)
299-
return
300-
}
301-
302-
if len(results) != 1000 {
303-
t.Errorf("Expected 1000 rows, got %d", len(results))
304-
return
305-
}
306-
307-
// Verify first and last rows
308-
if results[0].RowNum != 1 || results[0].Value != "row_1" {
309-
t.Errorf("First row incorrect: %+v", results[0])
310-
}
311-
if results[999].RowNum != 1000 || results[999].Value != "row_1000" {
312-
t.Errorf("Last row incorrect: %+v", results[999])
313-
}
314-
}
315-
316210
func TestSessionInfo(t *testing.T) {
317211
// Test USER function first
318212
var username string

tests/passed-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ TestRecoveryAfterInvalidQuery
6363
TestContextCancellationHandling
6464
TestConnectionPingAndHealth
6565
TestPoolStatisticsOverTime
66-
setupConnectionPoolTestTables
6766
TestNestedConnection
6867
TestMultipleSequentialConnections
6968
TestConnectionAfterDBClose

tests/query_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,3 +1664,35 @@ func TestNumberPrecision(t *testing.T) {
16641664
t.Errorf("Big number mismatch: expected %d, got %d", record.BigNumber, result.BigNumber)
16651665
}
16661666
}
1667+
1668+
func TestLargeResultSet(t *testing.T) {
1669+
var results []struct {
1670+
RowNum int `gorm:"column:ROW_NUM"`
1671+
Value string `gorm:"column:VALUE"`
1672+
}
1673+
1674+
query := `
1675+
SELECT LEVEL as row_num, 'row_' || LEVEL as value
1676+
FROM dual
1677+
CONNECT BY LEVEL <= 1000
1678+
`
1679+
1680+
err := DB.Raw(query).Scan(&results).Error
1681+
if err != nil {
1682+
t.Errorf("Failed to execute large result set query: %v", err)
1683+
return
1684+
}
1685+
1686+
if len(results) != 1000 {
1687+
t.Errorf("Expected 1000 rows, got %d", len(results))
1688+
return
1689+
}
1690+
1691+
// Verify first and last rows
1692+
if results[0].RowNum != 1 || results[0].Value != "row_1" {
1693+
t.Errorf("First row incorrect: %+v", results[0])
1694+
}
1695+
if results[999].RowNum != 1000 || results[999].Value != "row_1000" {
1696+
t.Errorf("Last row incorrect: %+v", results[999])
1697+
}
1698+
}

tests/transaction_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,77 @@ func TestTransactionWithRawSQL(t *testing.T) {
689689
t.Errorf("Expected age %d, got %d", user.Age+1, result.Age)
690690
}
691691
}
692+
693+
func TestTransactionCommit(t *testing.T) {
694+
// Create test table
695+
type TestTxTable struct {
696+
ID uint `gorm:"primaryKey"`
697+
Name string `gorm:"size:100;column:name"`
698+
}
699+
700+
err := DB.AutoMigrate(&TestTxTable{})
701+
if err != nil {
702+
t.Fatalf("Failed to migrate test table: %v", err)
703+
}
704+
defer DB.Migrator().DropTable(&TestTxTable{})
705+
706+
tx := DB.Begin()
707+
if tx.Error != nil {
708+
t.Fatalf("Failed to begin transaction: %v", tx.Error)
709+
}
710+
711+
record := TestTxTable{Name: "test_commit"}
712+
if err := tx.Create(&record).Error; err != nil {
713+
t.Errorf("Failed to create record in transaction: %v", err)
714+
}
715+
716+
if err := tx.Commit().Error; err != nil {
717+
t.Errorf("Failed to commit transaction: %v", err)
718+
}
719+
720+
// Verify record exists using quoted column name
721+
var count int64
722+
if err := DB.Model(&TestTxTable{}).Where("\"name\" = ?", "test_commit").Count(&count).Error; err != nil {
723+
t.Errorf("Failed to count records: %v", err)
724+
}
725+
if count != 1 {
726+
t.Errorf("Expected 1 record after commit, got %d", count)
727+
}
728+
}
729+
730+
func TestTransactionRollback(t *testing.T) {
731+
// Create test table
732+
type TestTxTable struct {
733+
ID uint `gorm:"primaryKey"`
734+
Name string `gorm:"size:100;column:name"`
735+
}
736+
737+
err := DB.AutoMigrate(&TestTxTable{})
738+
if err != nil {
739+
t.Fatalf("Failed to migrate test table: %v", err)
740+
}
741+
defer DB.Migrator().DropTable(&TestTxTable{})
742+
743+
tx := DB.Begin()
744+
if tx.Error != nil {
745+
t.Fatalf("Failed to begin transaction: %v", tx.Error)
746+
}
747+
748+
record := TestTxTable{Name: "test_rollback"}
749+
if err := tx.Create(&record).Error; err != nil {
750+
t.Errorf("Failed to create record in transaction: %v", err)
751+
}
752+
753+
if err := tx.Rollback().Error; err != nil {
754+
t.Errorf("Failed to rollback transaction: %v", err)
755+
}
756+
757+
// Verify record doesn't exist using quoted column name
758+
var count int64
759+
if err := DB.Model(&TestTxTable{}).Where("\"name\" = ?", "test_rollback").Count(&count).Error; err != nil {
760+
t.Errorf("Failed to count records: %v", err)
761+
}
762+
if count != 0 {
763+
t.Errorf("Expected 0 records after rollback, got %d", count)
764+
}
765+
}

0 commit comments

Comments
 (0)