2016-07-17 08:57:08 +02:00
|
|
|
{{- define "relationship_to_one_test_helper"}}
|
|
|
|
func Test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(t *testing.T) {
|
2016-07-15 08:15:35 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-07-15 06:49:22 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
var foreign {{.ForeignTable.NameGo}}
|
|
|
|
var local {{.LocalTable.NameGo}}
|
|
|
|
{{if .ForeignKey.Nullable -}}
|
|
|
|
local.{{.ForeignKey.Column | titleCase}}.Valid = true
|
2016-07-15 07:45:24 +02:00
|
|
|
{{end}}
|
2016-07-17 08:57:08 +02:00
|
|
|
{{- if .ForeignKey.ForeignColumnNullable -}}
|
|
|
|
foreign.{{.ForeignKey.ForeignColumn | titleCase}}.Valid = true
|
2016-07-15 07:45:24 +02:00
|
|
|
{{end}}
|
2016-07-15 06:49:22 +02:00
|
|
|
|
|
|
|
if err := foreign.InsertX(tx); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
local.{{.Function.LocalAssignment}} = foreign.{{.Function.ForeignAssignment}}
|
2016-07-15 06:49:22 +02:00
|
|
|
if err := local.InsertX(tx); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
checkForeign, err := local.{{.Function.Name}}X(tx)
|
2016-07-15 06:49:22 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
if checkForeign.{{.Function.ForeignAssignment}} != foreign.{{.Function.ForeignAssignment}} {
|
|
|
|
t.Errorf("want: %v, got %v", foreign.{{.Function.ForeignAssignment}}, checkForeign.{{.Function.ForeignAssignment}})
|
2016-07-15 06:49:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- if .Table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . -}}
|
|
|
|
{{- range .Table.FKeys -}}
|
|
|
|
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $dot.Table . -}}
|
|
|
|
{{- template "relationship_to_one_test_helper" $rel -}}
|
2016-07-15 06:49:22 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|