sqlboiler/templates_test/find.tpl

30 lines
1.1 KiB
Smarty
Raw Normal View History

{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func test{{$tableNamePlural}}Find(t *testing.T) {
t.Parallel()
2016-08-18 09:06:28 +02:00
seed := randomize.NewSeed()
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)
}
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-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-08-14 10:58:36 +02:00
if {{$varNameSingular}}Found == nil {
t.Error("want a record, got nil")
}
}