2016-03-28 10:17:41 +02:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
|
|
|
|
{{- $varNamePlural := camelCasePlural .Table.Name -}}
|
2016-06-10 04:09:48 +02:00
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
2016-03-21 06:15:14 +01:00
|
|
|
func Test{{$tableNamePlural}}All(t *testing.T) {
|
2016-05-17 12:00:56 +02:00
|
|
|
var err error
|
2016-03-21 06:15:14 +01:00
|
|
|
|
2016-06-08 07:45:34 +02:00
|
|
|
// Start from a clean slate
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
2016-06-10 06:40:02 +02:00
|
|
|
o := make({{$varNameSingular}}Slice, 2)
|
|
|
|
if err = boil.RandomizeSlice(&o); err != nil {
|
2016-06-10 07:44:20 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
2016-06-10 04:09:48 +02:00
|
|
|
}
|
2016-05-17 12:00:56 +02:00
|
|
|
|
|
|
|
// insert two random columns to test DeleteAll
|
2016-06-10 06:40:02 +02:00
|
|
|
for i := 0; i < len(o); i++ {
|
|
|
|
err = o[i].Insert()
|
2016-05-17 12:00:56 +02:00
|
|
|
if err != nil {
|
2016-06-10 06:40:02 +02:00
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
|
2016-05-17 12:00:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all rows to give a clean slate
|
|
|
|
err = {{$tableNamePlural}}().DeleteAll()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check number of rows in table to ensure DeleteAll was successful
|
|
|
|
var c int64
|
|
|
|
c, err = {{$tableNamePlural}}().Count()
|
|
|
|
|
|
|
|
if c != 0 {
|
|
|
|
t.Errorf("Expected {{.Table.Name}} table to be empty, but got %d rows", c)
|
|
|
|
}
|
|
|
|
|
2016-06-10 06:40:02 +02:00
|
|
|
o = make({{$varNameSingular}}Slice, 3)
|
2016-06-10 04:09:48 +02:00
|
|
|
if err = boil.RandomizeSlice(&o); err != nil {
|
2016-06-10 07:44:20 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
2016-06-10 04:09:48 +02:00
|
|
|
}
|
2016-05-17 12:00:56 +02:00
|
|
|
|
2016-06-08 07:45:34 +02:00
|
|
|
for i := 0; i < len(o); i++ {
|
|
|
|
err = o[i].Insert()
|
2016-05-17 12:00:56 +02:00
|
|
|
if err != nil {
|
2016-06-08 07:45:34 +02:00
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
|
2016-05-17 12:00:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 01:43:45 +02:00
|
|
|
// Ensure Count is valid
|
|
|
|
c, err = {{$tableNamePlural}}().Count()
|
|
|
|
if c != 3 {
|
|
|
|
t.Errorf("Expected {{.Table.Name}} table to have 3 rows, but got %d", c)
|
|
|
|
}
|
|
|
|
|
2016-05-17 12:00:56 +02:00
|
|
|
// Attempt to retrieve all objects
|
|
|
|
res, err := {{$tableNamePlural}}().All()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to retrieve all {{$tableNamePlural}}, err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(res) != 3 {
|
|
|
|
t.Errorf("Expected 3 {{$tableNameSingular}} rows, got %d", len(res))
|
|
|
|
}
|
2016-03-21 06:15:14 +01:00
|
|
|
}
|