-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1330 from atzedus/extract-relationship-test-tpl
relationship test extracted to standalone file
- Loading branch information
Showing
6 changed files
with
174 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// TestToOne tests cannot be run in parallel | ||
// or deadlocks can occur. | ||
func TestToOne(t *testing.T) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $fkey := .FKeys -}} | ||
{{- $ltable := $.Aliases.Table $fkey.Table -}} | ||
{{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} | ||
{{- $relAlias := $ltable.Relationship $fkey.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}", test{{$ltable.UpSingular}}ToOne{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) | ||
{{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) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToOneRelationships -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $ftable := $.Aliases.Table $rel.ForeignTable -}} | ||
{{- $relAlias := $ftable.Relationship $rel.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOne{{$ftable.UpSingular}}Using{{$relAlias.Local}}) | ||
{{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) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToManyRelationships -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToMany{{$relAlias.Local}}) | ||
{{end -}}{{- /* range */ -}} | ||
{{- end -}}{{- /* outer if join table */ -}} | ||
{{- end -}}{{- /* outer tables range */ -}} | ||
} | ||
|
||
// TestToOneSet tests cannot be run in parallel | ||
// or deadlocks can occur. | ||
func TestToOneSet(t *testing.T) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $fkey := .FKeys -}} | ||
{{- $ltable := $.Aliases.Table $fkey.Table -}} | ||
{{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} | ||
{{- $relAlias := $ltable.Relationship $fkey.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToOneSetOp{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) | ||
{{end -}}{{- /* fkey range */ -}} | ||
{{- end -}}{{- /* if join table */ -}} | ||
{{- end -}}{{- /* tables range */ -}} | ||
} | ||
|
||
// TestToOneRemove tests cannot be run in parallel | ||
// or deadlocks can occur. | ||
func TestToOneRemove(t *testing.T) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $fkey := .FKeys -}} | ||
{{- if $fkey.Nullable -}} | ||
{{- $ltable := $.Aliases.Table $fkey.Table -}} | ||
{{- $ftable := $.Aliases.Table $fkey.ForeignTable -}} | ||
{{- $relAlias := $ltable.Relationship $fkey.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToOneRemoveOp{{$ftable.UpSingular}}Using{{$relAlias.Foreign}}) | ||
{{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) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToOneRelationships -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $ftable := $.Aliases.Table $rel.ForeignTable -}} | ||
{{- $relAlias := $ftable.Relationship $rel.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOneSetOp{{$ftable.UpSingular}}Using{{$relAlias.Local}}) | ||
{{end -}}{{- /* range to one relationships */ -}} | ||
{{- 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 .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToOneRelationships -}} | ||
{{- if $rel.ForeignColumnNullable -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $ftable := $.Aliases.Table $rel.ForeignTable -}} | ||
{{- $relAlias := $ftable.Relationship $rel.Name -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$ftable.UpSingular}}Using{{$relAlias.Local}}", test{{$ltable.UpSingular}}OneToOneRemoveOp{{$ftable.UpSingular}}Using{{$relAlias.Local}}) | ||
{{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) { | ||
{{- range .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToManyRelationships -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManyAddOp{{$relAlias.Local}}) | ||
{{end -}}{{- /* range */ -}} | ||
{{- 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 .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToManyRelationships -}} | ||
{{- if not (or $rel.ForeignColumnNullable $rel.ToJoinTable)}} | ||
{{- else -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManySetOp{{$relAlias.Local}}) | ||
{{end -}}{{- /* if foreign column nullable */ -}} | ||
{{- 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 .Tables}} | ||
{{- if or .IsJoinTable .IsView -}} | ||
{{- else -}} | ||
{{- range $rel := .ToManyRelationships -}} | ||
{{- if not (or $rel.ForeignColumnNullable $rel.ToJoinTable)}} | ||
{{- else -}} | ||
{{- $ltable := $.Aliases.Table $rel.Table -}} | ||
{{- $relAlias := $.Aliases.ManyRelationship $rel.ForeignTable $rel.Name $rel.JoinTable $rel.JoinLocalFKeyName -}} | ||
t.Run("{{$ltable.UpSingular}}To{{$relAlias.Local}}", test{{$ltable.UpSingular}}ToManyRemoveOp{{$relAlias.Local}}) | ||
{{end -}}{{- /* if foreign column nullable */ -}} | ||
{{- end -}}{{- /* range */ -}} | ||
{{- end -}}{{- /* outer if join table */ -}} | ||
{{- end -}}{{- /* outer tables range */ -}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters