2016-09-18 20:13:11 +02:00
|
|
|
{{- if .Table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . -}}
|
|
|
|
{{- range .Table.FKeys -}}
|
2016-09-19 01:02:08 +02:00
|
|
|
{{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}}
|
2016-09-20 03:59:46 +02:00
|
|
|
{{- $varNameSingular := .Table | singular | camelCase -}}
|
2016-09-24 09:52:18 +02:00
|
|
|
{{- $foreignVarNameSingular := .ForeignTable | singular | camelCase}}
|
2016-09-21 05:58:21 +02:00
|
|
|
func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2016-07-15 06:49:22 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
var local {{$txt.LocalTable.NameGo}}
|
2016-09-19 01:40:33 +02:00
|
|
|
var foreign {{$txt.ForeignTable.NameGo}}
|
2016-09-19 09:03:29 +02:00
|
|
|
|
|
|
|
seed := randomize.NewSeed()
|
2016-09-20 03:59:46 +02:00
|
|
|
if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-09-19 09:03:29 +02:00
|
|
|
t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err)
|
|
|
|
}
|
2016-09-20 03:59:46 +02:00
|
|
|
if err := randomize.Struct(seed, &foreign, {{$foreignVarNameSingular}}DBTypes, true, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err)
|
|
|
|
}
|
2016-09-19 09:03:29 +02:00
|
|
|
|
2016-09-19 01:02:08 +02:00
|
|
|
{{if .Nullable -}}
|
2016-09-19 01:40:33 +02:00
|
|
|
local.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
|
|
|
{{- end}}
|
|
|
|
{{if .ForeignColumnNullable -}}
|
|
|
|
foreign.{{$txt.ForeignTable.ColumnNameGo}}.Valid = true
|
|
|
|
{{- end}}
|
2016-07-15 06:49:22 +02:00
|
|
|
|
2016-09-19 01:40:33 +02:00
|
|
|
if err := foreign.Insert(tx); err != nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-18 02:50:01 +02:00
|
|
|
|
2016-09-19 01:40:33 +02:00
|
|
|
local.{{$txt.Function.LocalAssignment}} = foreign.{{$txt.Function.ForeignAssignment}}
|
|
|
|
if err := local.Insert(tx); err != nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-15 06:49:22 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
check, err := local.{{$txt.Function.Name}}(tx).One()
|
2016-09-14 10:08:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-15 06:49:22 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
{{if $txt.Function.UsesBytes -}}
|
|
|
|
if 0 != bytes.Compare(check.{{$txt.Function.ForeignAssignment}}, foreign.{{$txt.Function.ForeignAssignment}}) {
|
2016-09-16 09:22:12 +02:00
|
|
|
{{else -}}
|
2016-09-18 20:13:11 +02:00
|
|
|
if check.{{$txt.Function.ForeignAssignment}} != foreign.{{$txt.Function.ForeignAssignment}} {
|
2016-09-16 09:22:12 +02:00
|
|
|
{{end -}}
|
2016-09-18 20:13:11 +02:00
|
|
|
t.Errorf("want: %v, got %v", foreign.{{$txt.Function.ForeignAssignment}}, check.{{$txt.Function.ForeignAssignment}})
|
2016-09-14 10:08:30 +02:00
|
|
|
}
|
2016-08-18 03:53:08 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
slice := {{$txt.LocalTable.NameGo}}Slice{&local}
|
|
|
|
if err = local.L.Load{{$txt.Function.Name}}(tx, false, &slice); err != nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-09-18 20:13:11 +02:00
|
|
|
if local.R.{{$txt.Function.Name}} == nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Error("struct should have been eager loaded")
|
|
|
|
}
|
2016-08-18 03:53:08 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
local.R.{{$txt.Function.Name}} = nil
|
|
|
|
if err = local.L.Load{{$txt.Function.Name}}(tx, true, &local); err != nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-09-18 20:13:11 +02:00
|
|
|
if local.R.{{$txt.Function.Name}} == nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Error("struct should have been eager loaded")
|
|
|
|
}
|
2016-07-15 06:49:22 +02:00
|
|
|
}
|
2016-09-24 09:52:18 +02:00
|
|
|
|
2016-09-18 20:13:11 +02:00
|
|
|
{{end -}}{{/* range */}}
|
|
|
|
{{- end -}}{{/* join table */}}
|