2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Find(t *testing.T) {
|
2016-08-15 05:14:39 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-18 09:06:28 +02:00
|
|
|
seed := randomize.NewSeed()
|
2016-08-15 05:14:39 +02:00
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-18 09:06:28 +02:00
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-06-10 07:44:20 +02:00
|
|
|
}
|
2016-06-10 10:53:15 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-08-14 10:58:36 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 10:53:15 +02:00
|
|
|
}
|
|
|
|
|
2016-09-01 03:16:21 +02:00
|
|
|
{{$varNameSingular}}Found, err := Find{{$tableNameSingular}}(tx, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice (printf "%s." $varNameSingular) | join ", "}})
|
2016-08-14 10:58:36 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 10:53:15 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if {{$varNameSingular}}Found == nil {
|
|
|
|
t.Error("want a record, got nil")
|
2016-06-10 10:53:15 +02:00
|
|
|
}
|
2016-06-10 07:44:20 +02:00
|
|
|
}
|