Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ package tests
import (
"fmt"
"testing"
"time"

. "github.com/oracle-samples/gorm-oracle/tests/utils"
)
Expand Down Expand Up @@ -90,3 +91,45 @@ func TestSetAndGet(t *testing.T) {
t.Errorf("Get non existing key should return error")
}
}

func TesUserInsertScenarios(t *testing.T) {
type UserWithAge struct {
ID uint `gorm:"column:ID;primaryKey"`
Name string `gorm:"column:NAME"`
Age int `gorm:"column:AGE"`
}

if err := DB.AutoMigrate(&UserWithAge{}); err != nil {
t.Fatalf("Failed to migrate table: %v", err)
}

user1 := UserWithAge{Name: "Alice", Age: 30}
if err := DB.Create(&user1).Error; err != nil {
t.Errorf("Basic insert failed: %v", err)
}

user2 := UserWithAge{Name: "Bob"}
if err := DB.Create(&user2).Error; err != nil {
t.Errorf("Insert with NULL failed: %v", err)
}

user3 := UserWithAge{Name: "O'Reilly", Age: 45}
if err := DB.Create(&user3).Error; err != nil {
t.Errorf("Insert with special characters failed: %v", err)
}

type UserWithTime struct {
ID uint `gorm:"column:ID;primaryKey"`
Name string `gorm:"column:NAME"`
CreatedAt time.Time `gorm:"column:CREATED_AT"`
}

if err := DB.AutoMigrate(&UserWithTime{}); err != nil {
t.Fatalf("Failed to migrate UserWithTime table: %v", err)
}

user4 := UserWithTime{Name: "Charlie"}
if err := DB.Create(&user4).Error; err != nil {
t.Errorf("Insert with default timestamp failed: %v", err)
}
}
1 change: 1 addition & 0 deletions tests/passed-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,4 @@ BenchmarkScanSlice
BenchmarkScanSlicePointer
BenchmarkUpdate
BenchmarkDelete
TesUserInsertScenarios
Loading