MCPcopy Index your code
hub / github.com/coder/coder / TestCustomQueriesSyncedRowScan

Function TestCustomQueriesSyncedRowScan

coderd/database/gentest/modelqueries_test.go:22–63  ·  view source on GitHub ↗

TestCustomQueriesSynced makes sure the manual custom queries in modelqueries.go are synced with the autogenerated queries.sql.go. This should probably be autogenerated, but it's not atm and this is easy to throw in to elevate a better error message. If this breaks, and is hard to fix, you can t.Ski

(t *testing.T)

Source from the content-addressed store, hash-verified

20// If this breaks, and is hard to fix, you can t.Skip() it. It is not a critical
21// test. Ping @Emyrk to fix it again.
22func TestCustomQueriesSyncedRowScan(t *testing.T) {
23 t.Parallel()
24
25 funcsToTrack := map[string]string{
26 "GetTemplatesWithFilter": "GetAuthorizedTemplates",
27 "GetWorkspaces": "GetAuthorizedWorkspaces",
28 "GetUsers": "GetAuthorizedUsers",
29 "GetChats": "GetAuthorizedChats",
30 }
31
32 // Scan custom
33 var custom []string
34 for _, fn := range funcsToTrack {
35 custom = append(custom, fn)
36 }
37
38 customFns := parseFile(t, "../modelqueries.go", func(name string) bool {
39 return slices.Contains(custom, name)
40 })
41 generatedFns := parseFile(t, "../queries.sql.go", func(name string) bool {
42 _, ok := funcsToTrack[name]
43 return ok
44 })
45 merged := customFns
46 for k, v := range generatedFns {
47 merged[k] = v
48 }
49
50 for a, b := range funcsToTrack {
51 a, b := a, b
52 if !compareFns(t, a, b, merged[a], merged[b]) {
53 //nolint:revive
54 defer func() {
55 // Run this at the end so the suggested fix is the last thing printed.
56 t.Errorf("The functions %q and %q need to have identical 'rows.Scan()' "+
57 "and 'db.QueryContext()' arguments in their function bodies. "+
58 "Make sure to copy the function body from the autogenerated %q body. "+
59 "Specifically the parameters for 'rows.Scan()' and 'db.QueryContext()'.", a, b, a)
60 }()
61 }
62 }
63}
64
65type parsedFunc struct {
66 RowScanArgs []ast.Expr

Callers

nothing calls this directly

Calls 4

parseFileFunction · 0.85
compareFnsFunction · 0.85
ContainsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected