2016-07-06 08:02:35 +02:00
|
|
|
{{- $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-07-15 14:26:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:48:33 +02:00
|
|
|
tx, err := boil.Begin()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-07-15 14:26:45 +02:00
|
|
|
}
|
2016-08-14 08:48:33 +02:00
|
|
|
defer tx.Rollback()
|
2016-07-15 14:26:45 +02:00
|
|
|
|
2016-08-14 08:48:33 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-07-15 14:26:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:48:33 +02:00
|
|
|
slice, err := {{$tableNamePlural}}(tx).All()
|
2016-07-15 14:26:45 +02:00
|
|
|
if err != nil {
|
2016-08-14 08:48:33 +02:00
|
|
|
t.Error(err)
|
2016-07-15 14:26:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:48:33 +02:00
|
|
|
if len(slice) != 1 {
|
|
|
|
t.Error("want one record, got:", len(slice))
|
2016-07-15 14:26:45 +02:00
|
|
|
}
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|