Skip to content

Commit 6e15fe1

Browse files
Add tests for Insert query
1 parent a9736f5 commit 6e15fe1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/main_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ package tests
4141
import (
4242
"fmt"
4343
"testing"
44+
"time"
4445

4546
. "github.com/oracle-samples/gorm-oracle/tests/utils"
4647
)
@@ -90,3 +91,37 @@ func TestSetAndGet(t *testing.T) {
9091
t.Errorf("Get non existing key should return error")
9192
}
9293
}
94+
95+
func TestInsertScenarios(t *testing.T) {
96+
if err := DB.Migrator().DropTable(&User{}); err != nil {
97+
t.Fatalf("Failed to drop table: %v", err)
98+
}
99+
if err := DB.AutoMigrate(&User{}); err != nil {
100+
t.Fatalf("Failed to migrate table: %v", err)
101+
}
102+
103+
user1 := User{Name: "Alice", Age: 30}
104+
if err := DB.Create(&user1).Error; err != nil {
105+
t.Errorf("Basic insert failed: %v", err)
106+
}
107+
108+
user2 := User{Name: "Bob"}
109+
if err := DB.Create(&user2).Error; err != nil {
110+
t.Errorf("Insert with NULL failed: %v", err)
111+
}
112+
113+
user3 := User{Name: "O'Reilly", Age: 45}
114+
if err := DB.Create(&user3).Error; err != nil {
115+
t.Errorf("Insert with special characters failed: %v", err)
116+
}
117+
118+
type UserWithTime struct {
119+
ID uint
120+
Name string
121+
CreatedAt time.Time
122+
}
123+
user4 := User{Name: "Charlie"}
124+
if err := DB.Create(&user4).Error; err != nil {
125+
t.Errorf("Insert with default timestamp failed: %v", err)
126+
}
127+
}

tests/passed-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,4 @@ BenchmarkScanSlice
379379
BenchmarkScanSlicePointer
380380
BenchmarkUpdate
381381
BenchmarkDelete
382+
TestInsertScenarios

0 commit comments

Comments
 (0)