2016-09-19 02:06:47 +02:00
|
|
|
{{- $dot := .}}
|
2016-08-15 11:36:38 +02:00
|
|
|
// This test suite runs each operation test in parallel.
|
|
|
|
// Example, if your database has 3 tables, the suite will run:
|
|
|
|
// table1, table2 and table3 Delete in parallel
|
|
|
|
// table1, table2 and table3 Insert in parallel, and so forth.
|
|
|
|
// It does NOT run each operation group in parallel.
|
|
|
|
// Separating the tests thusly grants avoidance of Postgres deadlocks.
|
2016-08-16 06:07:15 +02:00
|
|
|
func TestParent(t *testing.T) {
|
2016-08-15 11:36:38 +02:00
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}})
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDelete(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Delete)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestQueryDeleteAll(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}QueryDeleteAll)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSliceDeleteAll(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}SliceDeleteAll)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExists(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Exists)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFind(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Find)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
2016-08-16 06:07:15 +02:00
|
|
|
func TestBind(t *testing.T) {
|
2016-08-15 11:36:38 +02:00
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Bind)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOne(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}One)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAll(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}All)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCount(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Count)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
2016-09-21 06:07:50 +02:00
|
|
|
{{if not .NoHooks -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
func TestHooks(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Hooks)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
2016-08-28 12:48:50 +02:00
|
|
|
{{- end}}
|
2016-08-15 11:36:38 +02:00
|
|
|
|
|
|
|
func TestInsert(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Insert)
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}InsertWhitelist)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
2016-08-27 07:04:49 +02:00
|
|
|
// TestToOne tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToOne(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.FKeys -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-08-27 07:04:49 +02:00
|
|
|
{{end -}}{{- /* fkey range */ -}}
|
|
|
|
{{- end -}}{{- /* if join table */ -}}
|
|
|
|
{{- end -}}{{- /* tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-09-18 19:34:07 +02:00
|
|
|
// TestOneToOne tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestOneToOne(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToOneRelationships -}}
|
|
|
|
{{- $txt := txtsFromOneToOne $dot.Tables $table . -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-09-19 01:02:08 +02:00
|
|
|
{{end -}}{{- /* range */ -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:54:36 +02:00
|
|
|
// TestToMany tests cannot be run in parallel
|
2016-08-27 07:04:49 +02:00
|
|
|
// or deadlocks can occur.
|
2016-08-17 06:54:36 +02:00
|
|
|
func TestToMany(t *testing.T) {
|
2016-08-15 11:36:38 +02:00
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToManyRelationships -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
|
2016-09-19 01:02:08 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}})
|
|
|
|
{{end -}}{{- /* range */ -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-08-27 07:04:49 +02:00
|
|
|
// TestToOneSet tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToOneSet(t *testing.T) {
|
2016-08-17 06:54:36 +02:00
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.FKeys -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOneSetOp{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-08-17 06:54:36 +02:00
|
|
|
{{end -}}{{- /* fkey range */ -}}
|
|
|
|
{{- end -}}{{- /* if join table */ -}}
|
|
|
|
{{- end -}}{{- /* tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-08-27 07:04:49 +02:00
|
|
|
// TestToOneRemove tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToOneRemove(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.FKeys -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
|
|
|
|
{{- if $txt.ForeignKey.Nullable -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOneRemoveOp{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-08-27 07:04:49 +02:00
|
|
|
{{end -}}{{- /* if foreign key nullable */ -}}
|
|
|
|
{{- end -}}{{- /* fkey range */ -}}
|
|
|
|
{{- end -}}{{- /* if join table */ -}}
|
|
|
|
{{- end -}}{{- /* tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-09-18 19:34:07 +02:00
|
|
|
// TestOneToOneSet tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestOneToOneSet(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToOneRelationships -}}
|
2016-09-18 20:21:26 +02:00
|
|
|
{{- $txt := txtsFromOneToOne $dot.Tables $table . -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}OneToOneSetOp{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-09-19 02:06:47 +02:00
|
|
|
{{end -}}{{- /* range to one relationships */ -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestOneToOneRemove tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestOneToOneRemove(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
2016-09-19 01:02:08 +02:00
|
|
|
{{- range $table.ToOneRelationships -}}
|
2016-09-19 02:06:47 +02:00
|
|
|
{{- if .ForeignColumnNullable -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromOneToOne $dot.Tables $table . -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}OneToOneRemoveOp{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}})
|
2016-09-19 01:02:08 +02:00
|
|
|
{{end -}}{{- /* if foreign column nullable */ -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- end -}}{{- /* range */ -}}
|
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-08-27 07:04:49 +02:00
|
|
|
// TestToManyAdd tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToManyAdd(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToManyRelationships -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
|
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManyAddOp{{$txt.Function.Name}})
|
2016-09-19 01:02:08 +02:00
|
|
|
{{end -}}{{- /* range */ -}}
|
2016-08-27 07:04:49 +02:00
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestToManySet tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToManySet(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToManyRelationships -}}
|
2017-01-25 07:43:46 +01:00
|
|
|
{{- if not (or .ForeignColumnNullable .ToJoinTable)}}
|
2016-08-27 07:04:49 +02:00
|
|
|
{{- else -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
|
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManySetOp{{$txt.Function.Name}})
|
2016-09-19 01:02:08 +02:00
|
|
|
{{end -}}{{- /* if foreign column nullable */ -}}
|
2016-08-27 07:04:49 +02:00
|
|
|
{{- end -}}{{- /* range */ -}}
|
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestToManyRemove tests cannot be run in parallel
|
|
|
|
// or deadlocks can occur.
|
|
|
|
func TestToManyRemove(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- range $table.ToManyRelationships -}}
|
2017-01-25 07:43:46 +01:00
|
|
|
{{- if not (or .ForeignColumnNullable .ToJoinTable)}}
|
2016-08-27 07:04:49 +02:00
|
|
|
{{- else -}}
|
2016-09-18 19:34:07 +02:00
|
|
|
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
|
|
|
|
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManyRemoveOp{{$txt.Function.Name}})
|
2016-09-19 01:02:08 +02:00
|
|
|
{{end -}}{{- /* if foreign column nullable */ -}}
|
2016-08-27 07:04:49 +02:00
|
|
|
{{- end -}}{{- /* range */ -}}
|
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|
|
|
|
{{- end -}}{{- /* outer tables range */ -}}
|
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func TestReload(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Reload)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReloadAll(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}ReloadAll)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSelect(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Select)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdate(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Update)
|
2016-08-16 06:07:15 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSliceUpdateAll(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}SliceUpdateAll)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
|
|
|
}
|
2017-03-21 11:04:07 +01:00
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func TestUpsert(t *testing.T) {
|
|
|
|
{{- range $index, $table := .Tables}}
|
|
|
|
{{- if $table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $tableName := $table.Name | plural | titleCase -}}
|
|
|
|
t.Run("{{$tableName}}", test{{$tableName}}Upsert)
|
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|
2017-03-31 10:07:30 +02:00
|
|
|
}
|