Skip to content

Commit 1d333bb

Browse files
Fix test issues for TestInsertScenarios
1 parent 6e15fe1 commit 1d333bb

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

tests/main_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,45 @@ func TestSetAndGet(t *testing.T) {
9393
}
9494

9595
func TestInsertScenarios(t *testing.T) {
96-
if err := DB.Migrator().DropTable(&User{}); err != nil {
96+
type UserWithAge struct {
97+
ID uint `gorm:"column:ID;primaryKey"`
98+
Name string `gorm:"column:NAME"`
99+
Age int `gorm:"column:AGE"`
100+
}
101+
102+
if err := DB.Migrator().DropTable(&UserWithAge{}); err != nil {
97103
t.Fatalf("Failed to drop table: %v", err)
98104
}
99-
if err := DB.AutoMigrate(&User{}); err != nil {
105+
if err := DB.AutoMigrate(&UserWithAge{}); err != nil {
100106
t.Fatalf("Failed to migrate table: %v", err)
101107
}
102108

103-
user1 := User{Name: "Alice", Age: 30}
109+
user1 := UserWithAge{Name: "Alice", Age: 30}
104110
if err := DB.Create(&user1).Error; err != nil {
105111
t.Errorf("Basic insert failed: %v", err)
106112
}
107113

108-
user2 := User{Name: "Bob"}
114+
user2 := UserWithAge{Name: "Bob"}
109115
if err := DB.Create(&user2).Error; err != nil {
110116
t.Errorf("Insert with NULL failed: %v", err)
111117
}
112118

113-
user3 := User{Name: "O'Reilly", Age: 45}
119+
user3 := UserWithAge{Name: "O'Reilly", Age: 45}
114120
if err := DB.Create(&user3).Error; err != nil {
115121
t.Errorf("Insert with special characters failed: %v", err)
116122
}
117123

118124
type UserWithTime struct {
119-
ID uint
120-
Name string
121-
CreatedAt time.Time
125+
ID uint `gorm:"column:ID;primaryKey"`
126+
Name string `gorm:"column:NAME"`
127+
CreatedAt time.Time `gorm:"column:CREATED_AT"`
122128
}
123-
user4 := User{Name: "Charlie"}
129+
130+
if err := DB.AutoMigrate(&UserWithTime{}); err != nil {
131+
t.Fatalf("Failed to migrate UserWithTime table: %v", err)
132+
}
133+
134+
user4 := UserWithTime{Name: "Charlie"}
124135
if err := DB.Create(&user4).Error; err != nil {
125136
t.Errorf("Insert with default timestamp failed: %v", err)
126137
}

tests/run-tests.sh

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,9 @@
1010
# 2. Run the script ./run_tests.sh
1111

1212
# Check for required Oracle environment variables
13-
missing_vars=()
14-
for var in GORM_ORACLEDB_USER GORM_ORACLEDB_PASSWORD GORM_ORACLEDB_CONNECTSTRING GORM_ORACLEDB_LIBDIR; do
15-
if [ -z "${!var}" ]; then
16-
missing_vars+=("$var")
17-
fi
18-
done
19-
if [ ${#missing_vars[@]} -ne 0 ]; then
20-
echo "Error: The following environment variables must be set to run the tests: ${missing_vars[*]}"
21-
echo "Example:"
22-
echo " export GORM_ORACLEDB_USER=your_user"
23-
echo " export GORM_ORACLEDB_PASSWORD=your_password"
24-
echo " export GORM_ORACLEDB_CONNECTSTRING=your_connect_string"
25-
echo " export GORM_ORACLEDB_LIBDIR=your_lib_dir"
26-
exit 1
27-
fi
13+
export GORM_DSN='user="system" password="manager" \
14+
connectString="phoenix793630.dev3sub1phx.databasede3phx.oraclevcn.com:1661/cdb1_pdb1.regress.rdbms.dev.us.oracle.com" \
15+
libDir="/home/hkhasnis/projects/pkgs/23IC"'
2816

2917
# Check if passed-tests.txt exists
3018
if [ ! -f "passed-tests.txt" ]; then

tests/tests_test.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,9 @@ var newLogger = logger.New(
6565
},
6666
)
6767

68-
var oracleDSN = func() string {
69-
user := os.Getenv("GORM_ORACLEDB_USER")
70-
password := os.Getenv("GORM_ORACLEDB_PASSWORD")
71-
connectString := os.Getenv("GORM_ORACLEDB_CONNECTSTRING")
72-
libDir := os.Getenv("GORM_ORACLEDB_LIBDIR")
73-
74-
missing := []string{}
75-
if user == "" {
76-
missing = append(missing, "GORM_ORACLEDB_USER")
77-
}
78-
if password == "" {
79-
missing = append(missing, "GORM_ORACLEDB_PASSWORD")
80-
}
81-
if connectString == "" {
82-
missing = append(missing, "GORM_ORACLEDB_CONNECTSTRING")
83-
}
84-
if libDir == "" {
85-
missing = append(missing, "GORM_ORACLEDB_LIBDIR")
86-
}
87-
if len(missing) > 0 {
88-
log.Fatalf("Missing required environment variables: %v. Please set them to run the tests.", missing)
89-
}
90-
return `user="` + user + `" password="` + password + `"
91-
connectString="` + connectString + `"
92-
libDir="` + libDir + `"`
93-
}()
68+
var oracleDSN = `user="system" password="manager"
69+
connectString="phoenix793630.dev3sub1phx.databasede3phx.oraclevcn.com:1661/cdb1_pdb1.regress.rdbms.dev.us.oracle.com"
70+
libDir="/home/hkhasnis/projects/pkgs/23IC"`
9471

9572
func init() {
9673
var err error

0 commit comments

Comments
 (0)