Skip to content

Commit bdced58

Browse files
Merge pull request #41 from oracle-samples/Fix-distinct-tests
Fix distinct tests
2 parents 7c5ae82 + 3aef835 commit bdced58

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

tests/distinct_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,14 @@ func TestDistinctWithVaryingCase(t *testing.T) {
138138
}
139139

140140
func TestDistinctComputedColumn(t *testing.T) {
141-
t.Skip()
142141
type UserWithComputationColumn struct {
143142
ID int64 `gorm:"primary_key"`
144143
Name string
145144
Col int64
146145
}
147146

148147
if err := DB.Migrator().DropTable(&UserWithComputationColumn{}); err != nil {
149-
t.Fatalf("failed to drop table: %v", err)
148+
t.Logf("failed to drop table: %v", err)
150149
}
151150
if err := DB.AutoMigrate(&UserWithComputationColumn{}); err != nil {
152151
t.Fatalf("failed to migrate table: %v", err)
@@ -163,8 +162,8 @@ func TestDistinctComputedColumn(t *testing.T) {
163162

164163
var computedRecords []int
165164
if err := DB.
166-
Table("USER_WITH_COMPUTATION_COLUMNS").
167-
Select("DISTINCT col * 12 as Computed_Column").
165+
Table("user_with_computation_columns").
166+
Select("DISTINCT \"col\" * 12 as Computed_Column").
168167
Order("Computed_Column").
169168
Pluck("Computed_Column", &computedRecords).Error; err != nil {
170169
t.Fatalf("failed to query distinct Computed Columns: %v", err)
@@ -174,7 +173,6 @@ func TestDistinctComputedColumn(t *testing.T) {
174173
}
175174

176175
func TestDistinctWithAggregation(t *testing.T) {
177-
t.Skip()
178176
type UserWithComputationColumn struct {
179177
ID int64 `gorm:"primaryKey"`
180178
Name string
@@ -197,21 +195,21 @@ func TestDistinctWithAggregation(t *testing.T) {
197195
}
198196

199197
if err := DB.Create(&records).Error; err != nil {
200-
t.Fatalf("failed to insert test users: %v", err)
198+
t.Logf("failed to insert test users: %v", err)
201199
}
202200

203201
var result struct {
204-
Sum int64
202+
Sum float64
205203
Avg float64
206-
Count int64
204+
Count int
207205
}
208206

209207
err := DB.
210-
Table("USER_WITH_COMPUTATION_COLUMNS").
208+
Table("user_with_computation_columns").
211209
Select(`
212-
SUM(DISTINCT col) AS Sum,
213-
AVG(DISTINCT col) AS Avg,
214-
COUNT(DISTINCT col) AS Count
210+
SUM(DISTINCT "col") AS "sum",
211+
AVG(DISTINCT "col") AS "avg" ,
212+
COUNT(DISTINCT "col") AS "count"
215213
`).Scan(&result).Error
216214

217215
if err != nil {

0 commit comments

Comments
 (0)