2016-09-19 01:49:18 +02:00
|
|
|
{{- if .Table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . -}}
|
|
|
|
{{- range .Table.ToOneRelationships -}}
|
|
|
|
{{- $txt := txtsFromOneToOne $dot.Tables $dot.Table . -}}
|
2016-09-20 03:59:46 +02:00
|
|
|
{{- $varNameSingular := .Table | singular | camelCase -}}
|
|
|
|
{{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
|
2016-09-21 05:58:21 +02:00
|
|
|
func test{{$txt.LocalTable.NameGo}}OneToOne{{$txt.ForeignTable.NameGo}}Using{{$txt.Function.Name}}(t *testing.T) {
|
2016-09-19 01:49:18 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
|
|
|
var foreign {{$txt.ForeignTable.NameGo}}
|
|
|
|
var local {{$txt.LocalTable.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, &foreign, {{$foreignVarNameSingular}}DBTypes, true, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-09-19 09:03:29 +02:00
|
|
|
t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err)
|
|
|
|
}
|
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-19 01:49:18 +02:00
|
|
|
{{if .ForeignColumnNullable -}}
|
|
|
|
foreign.{{$txt.ForeignTable.ColumnNameGo}}.Valid = true
|
|
|
|
{{- end}}
|
|
|
|
{{if .Nullable -}}
|
|
|
|
local.{{$txt.LocalTable.ColumnNameGo}}.Valid = true
|
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
if err := local.Insert(tx); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
foreign.{{$txt.Function.ForeignAssignment}} = local.{{$txt.Function.LocalAssignment}}
|
|
|
|
if err := foreign.Insert(tx); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-19 01:52:46 +02:00
|
|
|
check, err := local.{{$txt.Function.Name}}(tx).One()
|
2016-09-19 01:49:18 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{{if $txt.Function.UsesBytes -}}
|
|
|
|
if 0 != bytes.Compare(check.{{$txt.Function.ForeignAssignment}}, foreign.{{$txt.Function.ForeignAssignment}}) {
|
|
|
|
{{else -}}
|
|
|
|
if check.{{$txt.Function.ForeignAssignment}} != foreign.{{$txt.Function.ForeignAssignment}} {
|
|
|
|
{{end -}}
|
|
|
|
t.Errorf("want: %v, got %v", foreign.{{$txt.Function.ForeignAssignment}}, check.{{$txt.Function.ForeignAssignment}})
|
|
|
|
}
|
|
|
|
|
|
|
|
slice := {{$txt.LocalTable.NameGo}}Slice{&local}
|
|
|
|
if err = local.L.Load{{$txt.Function.Name}}(tx, false, &slice); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if local.R.{{$txt.Function.Name}} == nil {
|
|
|
|
t.Error("struct should have been eager loaded")
|
|
|
|
}
|
|
|
|
|
|
|
|
local.R.{{$txt.Function.Name}} = nil
|
|
|
|
if err = local.L.Load{{$txt.Function.Name}}(tx, true, &local); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if local.R.{{$txt.Function.Name}} == nil {
|
|
|
|
t.Error("struct should have been eager loaded")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{end -}}{{/* range */}}
|
|
|
|
{{- end -}}{{/* join table */}}
|