2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $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++ {
|
2016-08-01 07:10:10 +02:00
|
|
|
if err = o[i].InsertG(); err != nil {
|
2016-06-10 10:53:15 +02:00
|
|
|
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-08-01 07:10:10 +02:00
|
|
|
j[i], err = {{$tableNameSingular}}FindG({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}})
|
2016-08-11 14:26:49 +02:00
|
|
|
err = {{$varNameSingular}}CompareVals(o[i], j[i], true); if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-06-10 10:53:15 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
f, err := {{$tableNameSingular}}FindG({{.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
|
|
|
|
2016-08-14 01:03:34 +02:00
|
|
|
colsWithoutPrimKeys := strmangle.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns)
|
2016-06-10 10:53:15 +02:00
|
|
|
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
|
|
|
}
|