Skip to content

Commit c7be77c

Browse files
committed
Add gorm tests
1 parent f38008e commit c7be77c

File tree

1 file changed

+45
-0
lines changed
  • go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package test
2+
3+
import "gorm.io/gorm"
4+
5+
type User struct{}
6+
7+
// test querying an Association
8+
func test_gorm_AssociationQuery(association *gorm.Association) {
9+
association.Find(&User{}) // $ source
10+
}
11+
12+
// test querying a ConnPool
13+
func test_gorm_ConnPoolQuery(connPool gorm.ConnPool) {
14+
rows, err := connPool.QueryContext(nil, "SELECT * FROM users") // $ source
15+
16+
if err != nil {
17+
return
18+
}
19+
20+
defer rows.Close()
21+
22+
userRow := connPool.QueryRowContext(nil, "SELECT * FROM users WHERE id = 1") // $ source
23+
24+
ignore(userRow)
25+
}
26+
27+
// test querying a DB
28+
func test_gorm_db(db *gorm.DB) {
29+
db.Find(&User{}) // $ source
30+
31+
db.FindInBatches(&User{}, 10, nil) // $ source
32+
33+
db.FirstOrCreate(&User{}) // $ source
34+
35+
db.FirstOrInit(&User{}) // $ source
36+
37+
db.First(&User{}) // $ source
38+
39+
db.Last(&User{}) // $ source
40+
41+
db.Take(&User{}) // $ source
42+
43+
db.Scan(&User{}) // $ source
44+
45+
}

0 commit comments

Comments
 (0)