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)
| 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. |
| 22 | func 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 | |
| 65 | type parsedFunc struct { |
| 66 | RowScanArgs []ast.Expr |
nothing calls this directly
no test coverage detected