github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/templates/test/singleton/boil_suites_test.go.tpl (about) 1 // This test suite runs each operation test in parallel. 2 // Example, if your database has 3 tables, the suite will run: 3 // table1, table2 and table3 Delete in parallel 4 // table1, table2 and table3 Insert in parallel, and so forth. 5 // It does NOT run each operation group in parallel. 6 // Separating the tests thusly grants avoidance of Postgres deadlocks. 7 func TestParent(t *testing.T) { 8 {{- range .Tables}} 9 {{- if or .IsJoinTable .IsView -}} 10 {{- else -}} 11 {{- $alias := $.Aliases.Table .Name -}} 12 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}) 13 {{end -}} 14 {{- end -}} 15 } 16 17 {{if .AddSoftDeletes -}} 18 func TestSoftDelete(t *testing.T) { 19 {{- range .Tables}} 20 {{- if or .IsJoinTable .IsView -}} 21 {{- else -}} 22 {{- if .CanSoftDelete $.AutoColumns.Deleted -}} 23 {{- $alias := $.Aliases.Table .Name -}} 24 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}SoftDelete) 25 {{end -}} 26 {{end -}} 27 {{- end -}} 28 } 29 30 func TestQuerySoftDeleteAll(t *testing.T) { 31 {{- range .Tables}} 32 {{- if or .IsJoinTable .IsView -}} 33 {{- else -}} 34 {{- if .CanSoftDelete $.AutoColumns.Deleted -}} 35 {{- $alias := $.Aliases.Table .Name -}} 36 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}QuerySoftDeleteAll) 37 {{end -}} 38 {{end -}} 39 {{- end -}} 40 } 41 42 func TestSliceSoftDeleteAll(t *testing.T) { 43 {{- range .Tables}} 44 {{- if or .IsJoinTable .IsView -}} 45 {{- else -}} 46 {{- if .CanSoftDelete $.AutoColumns.Deleted -}} 47 {{- $alias := $.Aliases.Table .Name -}} 48 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}SliceSoftDeleteAll) 49 {{end -}} 50 {{end -}} 51 {{- end -}} 52 } 53 {{- end}} 54 55 func TestDelete(t *testing.T) { 56 {{- range .Tables}} 57 {{- if or .IsJoinTable .IsView -}} 58 {{- else -}} 59 {{- $alias := $.Aliases.Table .Name -}} 60 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Delete) 61 {{end -}} 62 {{- end -}} 63 } 64 65 func TestQueryDeleteAll(t *testing.T) { 66 {{- range .Tables}} 67 {{- if or .IsJoinTable .IsView -}} 68 {{- else -}} 69 {{- $alias := $.Aliases.Table .Name -}} 70 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}QueryDeleteAll) 71 {{end -}} 72 {{- end -}} 73 } 74 75 func TestSliceDeleteAll(t *testing.T) { 76 {{- range .Tables}} 77 {{- if or .IsJoinTable .IsView -}} 78 {{- else -}} 79 {{- $alias := $.Aliases.Table .Name -}} 80 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}SliceDeleteAll) 81 {{end -}} 82 {{- end -}} 83 } 84 85 func TestExists(t *testing.T) { 86 {{- range .Tables}} 87 {{- if or .IsJoinTable .IsView -}} 88 {{- else -}} 89 {{- $alias := $.Aliases.Table .Name -}} 90 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Exists) 91 {{end -}} 92 {{- end -}} 93 } 94 95 func TestFind(t *testing.T) { 96 {{- range .Tables}} 97 {{- if or .IsJoinTable .IsView -}} 98 {{- else -}} 99 {{- $alias := $.Aliases.Table .Name -}} 100 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Find) 101 {{end -}} 102 {{- end -}} 103 } 104 105 func TestBind(t *testing.T) { 106 {{- range .Tables}} 107 {{- if or .IsJoinTable .IsView -}} 108 {{- else -}} 109 {{- $alias := $.Aliases.Table .Name -}} 110 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Bind) 111 {{end -}} 112 {{- end -}} 113 } 114 115 func TestOne(t *testing.T) { 116 {{- range .Tables}} 117 {{- if or .IsJoinTable .IsView -}} 118 {{- else -}} 119 {{- $alias := $.Aliases.Table .Name -}} 120 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}One) 121 {{end -}} 122 {{- end -}} 123 } 124 125 func TestAll(t *testing.T) { 126 {{- range .Tables}} 127 {{- if or .IsJoinTable .IsView -}} 128 {{- else -}} 129 {{- $alias := $.Aliases.Table .Name -}} 130 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}All) 131 {{end -}} 132 {{- end -}} 133 } 134 135 func TestCount(t *testing.T) { 136 {{- range .Tables}} 137 {{- if or .IsJoinTable .IsView -}} 138 {{- else -}} 139 {{- $alias := $.Aliases.Table .Name -}} 140 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Count) 141 {{end -}} 142 {{- end -}} 143 } 144 145 {{if not .NoHooks -}} 146 func TestHooks(t *testing.T) { 147 {{- range .Tables}} 148 {{- if or .IsJoinTable .IsView -}} 149 {{- else -}} 150 {{- $alias := $.Aliases.Table .Name -}} 151 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Hooks) 152 {{end -}} 153 {{- end -}} 154 } 155 {{- end}} 156 157 func TestInsert(t *testing.T) { 158 {{- range .Tables}} 159 {{- if or .IsJoinTable .IsView -}} 160 {{- else -}} 161 {{- $alias := $.Aliases.Table .Name -}} 162 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Insert) 163 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}InsertWhitelist) 164 {{end -}} 165 {{- end -}} 166 } 167 168 // TestToOne tests cannot be run in parallel 169 // or deadlocks can occur. 170 func TestToOne(t *testing.T) { 171 {{- range .Tables}} 172 {{- if or .IsJoinTable .IsView -}} 173 {{- else -}} 174 {{- range $fkey := .FKeys -}} 175 {{- $ltable := $.Aliases.Table $fkey.Table -}} 176 {{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} 177 {{- $relAlias := $ltable.Relationship $fkey.Name -}} 178 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}", test{{$ltable.UpSingular}}ToOne{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) 179 {{end -}}{{- /* fkey range */ -}} 180 {{- end -}}{{- /* if join table */ -}} 181 {{- end -}}{{- /* tables range */ -}} 182 } 183 184 // TestOneToOne tests cannot be run in parallel 185 // or deadlocks can occur. 186 func TestOneToOne(t *testing.T) { 187 {{- range .Tables}} 188 {{- if or .IsJoinTable .IsView -}} 189 {{- else -}} 190 {{- range $rel := .ToOneRelationships -}} 191 {{- $ltable := $.Aliases.Table $rel.Table -}} 192 {{- $ftable := $.Aliases.Table $rel.ForeignTable -}} 193 {{- $relAlias := $ftable.Relationship $rel.Name -}} 194 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOne{{$ftable.UpSingular}}Using{{$relAlias.Local}}) 195 {{end -}}{{- /* range */ -}} 196 {{- end -}}{{- /* outer if join table */ -}} 197 {{- end -}}{{- /* outer tables range */ -}} 198 } 199 200 // TestToMany tests cannot be run in parallel 201 // or deadlocks can occur. 202 func TestToMany(t *testing.T) { 203 {{- range .Tables}} 204 {{- if or .IsJoinTable .IsView -}} 205 {{- else -}} 206 {{- range $rel := .ToManyRelationships -}} 207 {{- $ltable := $.Aliases.Table $rel.Table -}} 208 {{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} 209 t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToMany{{$relAlias.Local}}) 210 {{end -}}{{- /* range */ -}} 211 {{- end -}}{{- /* outer if join table */ -}} 212 {{- end -}}{{- /* outer tables range */ -}} 213 } 214 215 // TestToOneSet tests cannot be run in parallel 216 // or deadlocks can occur. 217 func TestToOneSet(t *testing.T) { 218 {{- range .Tables}} 219 {{- if or .IsJoinTable .IsView -}} 220 {{- else -}} 221 {{- range $fkey := .FKeys -}} 222 {{- $ltable := $.Aliases.Table $fkey.Table -}} 223 {{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} 224 {{- $relAlias := $ltable.Relationship $fkey.Name -}} 225 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToOneSetOp{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) 226 {{end -}}{{- /* fkey range */ -}} 227 {{- end -}}{{- /* if join table */ -}} 228 {{- end -}}{{- /* tables range */ -}} 229 } 230 231 // TestToOneRemove tests cannot be run in parallel 232 // or deadlocks can occur. 233 func TestToOneRemove(t *testing.T) { 234 {{- range .Tables}} 235 {{- if or .IsJoinTable .IsView -}} 236 {{- else -}} 237 {{- range $fkey := .FKeys -}} 238 {{- if $fkey.Nullable -}} 239 {{- $ltable := $.Aliases.Table $fkey.Table -}} 240 {{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} 241 {{- $relAlias := $ltable.Relationship $fkey.Name -}} 242 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToOneRemoveOp{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) 243 {{end -}}{{- /* if foreign key nullable */ -}} 244 {{- end -}}{{- /* fkey range */ -}} 245 {{- end -}}{{- /* if join table */ -}} 246 {{- end -}}{{- /* tables range */ -}} 247 } 248 249 // TestOneToOneSet tests cannot be run in parallel 250 // or deadlocks can occur. 251 func TestOneToOneSet(t *testing.T) { 252 {{- range .Tables}} 253 {{- if or .IsJoinTable .IsView -}} 254 {{- else -}} 255 {{- range $rel := .ToOneRelationships -}} 256 {{- $ltable := $.Aliases.Table $rel.Table -}} 257 {{- $ftable := $.Aliases.Table $rel.ForeignTable -}} 258 {{- $relAlias := $ftable.Relationship $rel.Name -}} 259 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOneSetOp{{$ftable.UpSingular}}Using{{$relAlias.Local}}) 260 {{end -}}{{- /* range to one relationships */ -}} 261 {{- end -}}{{- /* outer if join table */ -}} 262 {{- end -}}{{- /* outer tables range */ -}} 263 } 264 265 // TestOneToOneRemove tests cannot be run in parallel 266 // or deadlocks can occur. 267 func TestOneToOneRemove(t *testing.T) { 268 {{- range .Tables}} 269 {{- if or .IsJoinTable .IsView -}} 270 {{- else -}} 271 {{- range $rel := .ToOneRelationships -}} 272 {{- if $rel.ForeignColumnNullable -}} 273 {{- $ltable := $.Aliases.Table $rel.Table -}} 274 {{- $ftable := $.Aliases.Table $rel.ForeignTable -}} 275 {{- $relAlias := $ftable.Relationship $rel.Name -}} 276 t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOneRemoveOp{{$ftable.UpSingular}}Using{{$relAlias.Local}}) 277 {{end -}}{{- /* if foreign column nullable */ -}} 278 {{- end -}}{{- /* range */ -}} 279 {{- end -}}{{- /* outer if join table */ -}} 280 {{- end -}}{{- /* outer tables range */ -}} 281 } 282 283 // TestToManyAdd tests cannot be run in parallel 284 // or deadlocks can occur. 285 func TestToManyAdd(t *testing.T) { 286 {{- range .Tables}} 287 {{- if or .IsJoinTable .IsView -}} 288 {{- else -}} 289 {{- range $rel := .ToManyRelationships -}} 290 {{- $ltable := $.Aliases.Table $rel.Table -}} 291 {{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} 292 t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManyAddOp{{$relAlias.Local}}) 293 {{end -}}{{- /* range */ -}} 294 {{- end -}}{{- /* outer if join table */ -}} 295 {{- end -}}{{- /* outer tables range */ -}} 296 } 297 298 // TestToManySet tests cannot be run in parallel 299 // or deadlocks can occur. 300 func TestToManySet(t *testing.T) { 301 {{- range .Tables}} 302 {{- if or .IsJoinTable .IsView -}} 303 {{- else -}} 304 {{- range $rel := .ToManyRelationships -}} 305 {{- if not (or $rel.ForeignColumnNullable $rel.ToJoinTable)}} 306 {{- else -}} 307 {{- $ltable := $.Aliases.Table $rel.Table -}} 308 {{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} 309 t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManySetOp{{$relAlias.Local}}) 310 {{end -}}{{- /* if foreign column nullable */ -}} 311 {{- end -}}{{- /* range */ -}} 312 {{- end -}}{{- /* outer if join table */ -}} 313 {{- end -}}{{- /* outer tables range */ -}} 314 } 315 316 // TestToManyRemove tests cannot be run in parallel 317 // or deadlocks can occur. 318 func TestToManyRemove(t *testing.T) { 319 {{- range .Tables}} 320 {{- if or .IsJoinTable .IsView -}} 321 {{- else -}} 322 {{- range $rel := .ToManyRelationships -}} 323 {{- if not (or $rel.ForeignColumnNullable $rel.ToJoinTable)}} 324 {{- else -}} 325 {{- $ltable := $.Aliases.Table $rel.Table -}} 326 {{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} 327 t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManyRemoveOp{{$relAlias.Local}}) 328 {{end -}}{{- /* if foreign column nullable */ -}} 329 {{- end -}}{{- /* range */ -}} 330 {{- end -}}{{- /* outer if join table */ -}} 331 {{- end -}}{{- /* outer tables range */ -}} 332 } 333 334 func TestReload(t *testing.T) { 335 {{- range .Tables}} 336 {{- if or .IsJoinTable .IsView -}} 337 {{- else -}} 338 {{- $alias := $.Aliases.Table .Name -}} 339 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Reload) 340 {{end -}} 341 {{- end -}} 342 } 343 344 func TestReloadAll(t *testing.T) { 345 {{- range .Tables}} 346 {{- if or .IsJoinTable .IsView -}} 347 {{- else -}} 348 {{- $alias := $.Aliases.Table .Name -}} 349 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}ReloadAll) 350 {{end -}} 351 {{- end -}} 352 } 353 354 func TestSelect(t *testing.T) { 355 {{- range .Tables}} 356 {{- if or .IsJoinTable .IsView -}} 357 {{- else -}} 358 {{- $alias := $.Aliases.Table .Name -}} 359 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Select) 360 {{end -}} 361 {{- end -}} 362 } 363 364 func TestUpdate(t *testing.T) { 365 {{- range .Tables}} 366 {{- if or .IsJoinTable .IsView -}} 367 {{- else -}} 368 {{- $alias := $.Aliases.Table .Name -}} 369 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}Update) 370 {{end -}} 371 {{- end -}} 372 } 373 374 func TestSliceUpdateAll(t *testing.T) { 375 {{- range .Tables}} 376 {{- if or .IsJoinTable .IsView -}} 377 {{- else -}} 378 {{- $alias := $.Aliases.Table .Name -}} 379 t.Run("{{$alias.UpPlural}}", test{{$alias.UpPlural}}SliceUpdateAll) 380 {{end -}} 381 {{- end -}} 382 }