Fix test suites to include one-to-one

This commit is contained in:
Aaron L 2016-09-18 10:34:07 -07:00
parent 4d45a03ff7
commit dcbc640303

View file

@ -135,13 +135,29 @@ func TestToOne(t *testing.T) {
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.FKeys -}}
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}To{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToOne{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}})
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}})
{{end -}}{{- /* fkey range */ -}}
{{- end -}}{{- /* if join table */ -}}
{{- end -}}{{- /* tables range */ -}}
}
// TestOneToOne tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOne(t *testing.T) {
{{- $dot := .}}
{{- range $index, $table := .Tables}}
{{- $tableName := $table.Name | plural | titleCase -}}
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.ToOneRelationships -}}
{{- $txt := txtsFromOneToOne $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}})
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}
{{- end -}}{{- /* outer tables range */ -}}
}
// TestToMany tests cannot be run in parallel
// or deadlocks can occur.
func TestToMany(t *testing.T) {
@ -151,8 +167,8 @@ func TestToMany(t *testing.T) {
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.ToManyRelationships -}}
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}})
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToMany{{$txt.Function.Name}})
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}
{{- end -}}{{- /* outer tables range */ -}}
@ -166,8 +182,8 @@ func TestToOneSet(t *testing.T) {
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.FKeys -}}
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}To{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToOneSetOp{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}})
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOneSetOp{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}})
{{end -}}{{- /* fkey range */ -}}
{{- end -}}{{- /* if join table */ -}}
{{- end -}}{{- /* tables range */ -}}
@ -181,15 +197,53 @@ func TestToOneRemove(t *testing.T) {
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.FKeys -}}
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $table . -}}
{{- if $rel.ForeignKey.Nullable -}}
t.Run("{{$rel.LocalTable.NameGo}}To{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToOneRemoveOp{{$rel.ForeignTable.NameGo}}_{{$rel.Function.Name}})
{{- $txt := txtsFromFKey $dot.Tables $table . -}}
{{- if $txt.ForeignKey.Nullable -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToOneRemoveOp{{$txt.ForeignTable.NameGo}}_{{$txt.Function.Name}})
{{end -}}{{- /* if foreign key nullable */ -}}
{{- end -}}{{- /* fkey range */ -}}
{{- end -}}{{- /* if join table */ -}}
{{- end -}}{{- /* tables range */ -}}
}
// TestOneToOneSet tests cannot be run in parallel
// or deadlocks can occur.
func TestOneToOneSet(t *testing.T) {
{{- $dot := .}}
{{- range $index, $table := .Tables}}
{{- $tableName := $table.Name | plural | titleCase -}}
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.ToOneRelationships -}}
{{- if not .ForeignColumnNullable -}}
{{- else -}}
{{- $txt := textsFrom $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}OneToOneSetOp{{$txt.Function.Name}})
{{- end -}}{{- /* if foreign column nullable */ -}}
{{- end -}}{{- /* range */ -}}
{{- 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) {
{{- $dot := .}}
{{- range $index, $table := .Tables}}
{{- $tableName := $table.Name | plural | titleCase -}}
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.OneToOneRelationships -}}
{{- if not .ForeignColumnNullable -}}
{{- else -}}
{{- $txt := txtsFromOneToOne $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}OneToOneRemoveOp{{$txt.Function.Name}})
{{- end -}}{{- /* if foreign column nullable */ -}}
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}
{{- end -}}{{- /* outer tables range */ -}}
}
// TestToManyAdd tests cannot be run in parallel
// or deadlocks can occur.
func TestToManyAdd(t *testing.T) {
@ -199,8 +253,8 @@ func TestToManyAdd(t *testing.T) {
{{- if $table.IsJoinTable -}}
{{- else -}}
{{- range $table.ToManyRelationships -}}
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}})
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManyAddOp{{$txt.Function.Name}})
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}
{{- end -}}{{- /* outer tables range */ -}}
@ -217,8 +271,8 @@ func TestToManySet(t *testing.T) {
{{- range $table.ToManyRelationships -}}
{{- if not .ForeignColumnNullable -}}
{{- else -}}
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManySetOp{{$rel.Function.Name}})
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManySetOp{{$txt.Function.Name}})
{{- end -}}{{- /* if foreign column nullable */ -}}
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}
@ -236,8 +290,8 @@ func TestToManyRemove(t *testing.T) {
{{- range $table.ToManyRelationships -}}
{{- if not .ForeignColumnNullable -}}
{{- else -}}
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManyRemoveOp{{$rel.Function.Name}})
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
t.Run("{{$txt.LocalTable.NameGo}}To{{$txt.Function.Name}}", test{{$txt.LocalTable.NameGo}}ToManyRemoveOp{{$txt.Function.Name}})
{{- end -}}{{- /* if foreign column nullable */ -}}
{{- end -}}{{- /* range */ -}}
{{- end -}}{{- /* outer if join table */ -}}