Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 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,37 @@ func TestSetAndGet(t *testing.T) {
t.Errorf("Get non existing key should return error")
}
}

func TestInsertScenarios(t *testing.T) {
if err := DB.Migrator().DropTable(&User{}); err != nil {
t.Fatalf("Failed to drop table: %v", err)
}
if err := DB.AutoMigrate(&User{}); err != nil {
t.Fatalf("Failed to migrate table: %v", err)
}

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

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

user3 := User{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
Name string
CreatedAt time.Time
}
user4 := User{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
TestInsertScenarios
Loading