Skip to content

Commit 26b30c1

Browse files
committed
fix(sqlitecgo): update tests for bug gogf#4698 fix - expect success instead of error
After fixing gogf#4698 (AllAndCount/ScanAndCount always use COUNT(1)), SQLiteCGo tests expecting CodeDbOperationError now pass correctly. Updated tests: - Test_Model_AllAndCount: AllAndCount(true) with multiple fields - Test_Model_ScanAndCount: ScanAndCount with multiple fields Both now verify correct behavior (COUNT(1) usage) instead of expecting the old buggy behavior (COUNT syntax error). Related: gogf#4698
1 parent 14dc97b commit 26b30c1

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

contrib/drivers/sqlitecgo/sqlitecgo_z_unit_model_test.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -657,17 +657,22 @@ func Test_Model_AllAndCount(t *testing.T) {
657657
t.Assert(all[0]["passport"], "user_1")
658658
t.Assert(count, 1)
659659
})
660-
// AllAndCount with Join return CodeDbOperationError
660+
// AllAndCount with Join and useFieldForCount=true
661+
// Regression test for #4698 - verifies COUNT(1) is used instead of COUNT(multiple fields)
661662
gtest.C(t, func(t *gtest.T) {
662663
all, count, err := db.Model(table).As("u1").
663664
LeftJoin(tableName2, "u2", "u2.id=u1.id").
664665
Fields("u1.passport,u1.id,u2.name,u2.age").
665666
Where("u1.id<2").
666667
AllAndCount(true)
667-
t.AssertNE(err, nil)
668-
t.AssertEQ(gerror.Code(err), gcode.CodeDbOperationError)
669-
t.Assert(count, 0)
670-
t.Assert(all, nil)
668+
t.AssertNil(err)
669+
t.Assert(len(all), 1)
670+
t.Assert(len(all[0]), 4)
671+
t.Assert(all[0]["id"], 1)
672+
t.Assert(all[0]["age"], 18)
673+
t.Assert(all[0]["name"], "table2_1")
674+
t.Assert(all[0]["passport"], "user_1")
675+
t.Assert(count, 1)
671676
})
672677
}
673678

@@ -1334,7 +1339,8 @@ func Test_Model_ScanAndCount(t *testing.T) {
13341339
t.Assert(count, 1)
13351340
t.AssertEQ(users[0].Name, "table2_1")
13361341
})
1337-
// ScanAndCount with join return CodeDbOperationError
1342+
// ScanAndCount with join and useFieldForCount=true
1343+
// Regression test for #4698 - verifies COUNT(1) is used instead of COUNT(multiple fields)
13381344
gtest.C(t, func(t *gtest.T) {
13391345
type User struct {
13401346
Id int
@@ -1349,10 +1355,13 @@ func Test_Model_ScanAndCount(t *testing.T) {
13491355
Fields("u1.passport,u1.id,u2.name,u2.age").
13501356
Where("u1.id<2").
13511357
ScanAndCount(&users, &count, true)
1352-
t.AssertNE(err, nil)
1353-
t.Assert(gerror.Code(err), gcode.CodeDbOperationError)
1354-
t.Assert(count, 0)
1355-
t.AssertEQ(users, nil)
1358+
t.AssertNil(err)
1359+
t.Assert(len(users), 1)
1360+
t.Assert(count, 1)
1361+
t.Assert(users[0].Id, 1)
1362+
t.Assert(users[0].Age, 18)
1363+
t.Assert(users[0].Name, "table2_1")
1364+
t.Assert(users[0].Passport, "user_1")
13561365
})
13571366
}
13581367

0 commit comments

Comments
 (0)