sqlboiler/templates_test/select.tpl

32 lines
926 B
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}}Select(t *testing.T) {
2016-08-14 10:58:36 +02:00
t.Parallel()
2016-08-14 08:48:33 +02:00
{{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
}
2016-08-14 08:48:33 +02:00
tx, err := boil.Begin()
if err != nil {
t.Fatal(err)
}
2016-08-14 08:48:33 +02:00
defer tx.Rollback()
2016-08-14 08:48:33 +02:00
if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err)
}
2016-08-14 08:48:33 +02:00
slice, err := {{$tableNamePlural}}(tx).All()
if err != nil {
2016-08-14 08:48:33 +02:00
t.Error(err)
}
2016-08-14 08:48:33 +02:00
if len(slice) != 1 {
t.Error("want one record, got:", len(slice))
}
}