2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
2016-06-10 07:44:20 +02:00
|
|
|
{{- $dbName := singular .Table.Name -}}
|
2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-06-10 07:44:20 +02:00
|
|
|
func Test{{$tableNamePlural}}Find(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
2016-07-16 16:15:14 +02:00
|
|
|
o := make({{$tableNameSingular}}Slice, 3)
|
2016-07-14 07:09:05 +02:00
|
|
|
if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-06-10 07:44:20 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
|
|
|
}
|
2016-06-10 10:53:15 +02:00
|
|
|
|
|
|
|
for i := 0; i < len(o); i++ {
|
|
|
|
if err = o[i].Insert(); err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 16:15:14 +02:00
|
|
|
j := make({{$tableNameSingular}}Slice, 3)
|
2016-06-10 10:53:15 +02:00
|
|
|
// Perform all Find queries and assign result objects to slice for comparison
|
|
|
|
for i := 0; i < len(j); i++ {
|
2016-06-20 07:57:46 +02:00
|
|
|
j[i], err = {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}})
|
2016-06-14 16:01:28 +02:00
|
|
|
{{$varNameSingular}}CompareVals(o[i], j[i], t)
|
2016-06-10 10:53:15 +02:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:57:46 +02:00
|
|
|
f, err := {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[0]." | join ", "}}, {{$varNameSingular}}PrimaryKeyColumns...)
|
2016-06-10 10:53:15 +02:00
|
|
|
{{range $key, $value := .Table.PKey.Columns}}
|
|
|
|
if o[0].{{titleCase $value}} != f.{{titleCase $value}} {
|
|
|
|
t.Errorf("Expected primary key values to match, {{titleCase $value}} did not match")
|
|
|
|
}
|
2016-07-13 18:51:40 +02:00
|
|
|
{{end}}
|
2016-06-10 10:53:15 +02:00
|
|
|
|
|
|
|
colsWithoutPrimKeys := boil.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns)
|
|
|
|
fRef := reflect.ValueOf(f).Elem()
|
|
|
|
for _, v := range colsWithoutPrimKeys {
|
|
|
|
val := fRef.FieldByName(v)
|
|
|
|
if val.IsValid() {
|
|
|
|
t.Errorf("Expected all other columns to be zero value, but column %s was %#v", v, val.Interface())
|
|
|
|
}
|
|
|
|
}
|
2016-07-15 07:32:36 +02:00
|
|
|
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
2016-06-10 07:44:20 +02:00
|
|
|
}
|