2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
2016-06-10 16:22:08 +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 16:22:08 +02:00
|
|
|
func Test{{$tableNamePlural}}Bind(t *testing.T) {
|
2016-06-14 16:01:28 +02:00
|
|
|
var err error
|
|
|
|
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
|
|
|
o := {{$tableNameSingular}}{}
|
2016-07-13 18:51:40 +02:00
|
|
|
if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes); err != nil {
|
2016-06-14 16:01:28 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = o.Insert(); err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
j := {{$tableNameSingular}}{}
|
2016-06-10 16:22:08 +02:00
|
|
|
|
2016-06-26 05:17:39 +02:00
|
|
|
err = {{$tableNamePlural}}(qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})).Bind(&j)
|
2016-06-14 16:01:28 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to call Bind on {{$tableNameSingular}} single object: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{{$varNameSingular}}CompareVals(&o, &j, t)
|
2016-06-14 18:15:58 +02:00
|
|
|
|
|
|
|
// insert 3 rows, attempt to bind into slice
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
|
|
|
y := make({{$varNameSingular}}Slice, 3)
|
2016-07-13 18:51:40 +02:00
|
|
|
if err = boil.RandomizeSlice(&y, {{$varNameSingular}}DBTypes); err != nil {
|
2016-06-14 18:15:58 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert random columns to test DeleteAll
|
|
|
|
for i := 0; i < len(y); i++ {
|
|
|
|
err = y[i].Insert()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", y[i], err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
k := {{$varNameSingular}}Slice{}
|
|
|
|
err = {{$tableNamePlural}}().Bind(&k)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to call Bind on {{$tableNameSingular}} slice of objects: %s", err)
|
|
|
|
}
|
2016-06-20 07:22:50 +02:00
|
|
|
|
2016-06-14 18:15:58 +02:00
|
|
|
if len(k) != 3 {
|
|
|
|
t.Errorf("Expected 3 results, got %d", len(k))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(y); i++ {
|
|
|
|
{{$varNameSingular}}CompareVals(y[i], k[i], t)
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test{{$tableNamePlural}}One(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
|
|
|
o := {{$tableNameSingular}}{}
|
2016-07-13 18:51:40 +02:00
|
|
|
if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes); err != nil {
|
2016-06-10 16:22:08 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = o.Insert(); err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := {{$tableNamePlural}}().One()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to fetch One {{$tableNameSingular}} result:\n#%v\nErr: %s", j, err)
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:01:28 +02:00
|
|
|
{{$varNameSingular}}CompareVals(&o, j, t)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test{{$tableNamePlural}}All(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
|
|
|
o := make({{$varNameSingular}}Slice, 3)
|
2016-07-13 18:51:40 +02:00
|
|
|
if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes); err != nil {
|
2016-06-10 16:22:08 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert random columns to test DeleteAll
|
|
|
|
for i := 0; i < len(o); i++ {
|
|
|
|
err = o[i].Insert()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := {{$tableNamePlural}}().All()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to fetch All {{$tableNameSingular}} results: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(j) != 3 {
|
|
|
|
t.Errorf("Expected 3 results, got %d", len(j))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(o); i++ {
|
2016-06-14 16:01:28 +02:00
|
|
|
{{$varNameSingular}}CompareVals(o[i], j[i], t)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test{{$tableNamePlural}}Count(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
{{$varNamePlural}}DeleteAllRows(t)
|
|
|
|
|
2016-06-11 10:30:56 +02:00
|
|
|
o := make({{$varNameSingular}}Slice, 3)
|
2016-07-13 18:51:40 +02:00
|
|
|
if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes); err != nil {
|
2016-06-10 16:22:08 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:15:32 +02:00
|
|
|
// insert random columns to test Count
|
2016-06-10 16:22:08 +02:00
|
|
|
for i := 0; i < len(o); i++ {
|
|
|
|
err = o[i].Insert()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 15:15:32 +02:00
|
|
|
|
|
|
|
c, err := {{$tableNamePlural}}().Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to count query {{$tableNameSingular}}: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c != 3 {
|
|
|
|
t.Errorf("Expected 3 results from count {{$tableNameSingular}}, got %d", c)
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|