sqlboiler/templates_test/select.tpl

30 lines
937 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-18 09:06:28 +02:00
seed := randomize.NewSeed()
var err error
2016-08-14 08:48:33 +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 08:48:33 +02:00
defer tx.Rollback()
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))
}
}