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-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Bind(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
2016-06-14 16:01:28 +02:00
|
|
|
|
2016-08-15 05:44:59 +02:00
|
|
|
seed := boil.NewSeed()
|
2016-08-15 05:14:39 +02:00
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$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)
|
2016-06-14 18:15:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-08-14 10:58:36 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-14 18:15:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$tableNamePlural}}(tx).Bind({{$varNameSingular}}); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-14 18:15:58 +02:00
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}One(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
2016-06-10 16:22:08 +02:00
|
|
|
|
2016-08-15 05:44:59 +02:00
|
|
|
seed := boil.NewSeed()
|
2016-08-15 05:14:39 +02:00
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$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)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-08-14 10:58:36 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
2016-08-11 14:26:49 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-07-15 07:32:36 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if x, err := {{$tableNamePlural}}(tx).One(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
} else if x == nil {
|
|
|
|
t.Error("expected to get a non nil record")
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}All(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
2016-06-10 16:22:08 +02:00
|
|
|
|
2016-08-15 05:44:59 +02:00
|
|
|
seed := boil.NewSeed()
|
2016-08-15 05:14:39 +02:00
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
|
|
|
|
{{$varNameSingular}}Two := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-08-14 10:58:36 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if err = {{$varNameSingular}}Two.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
slice, err := {{$tableNamePlural}}(tx).All()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
2016-07-15 07:32:36 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if len(slice) != 2 {
|
|
|
|
t.Error("want 2 records, got:", len(slice))
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Count(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
2016-06-10 16:22:08 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
var err error
|
2016-08-15 05:44:59 +02:00
|
|
|
seed := boil.NewSeed()
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
|
|
|
|
{{$varNameSingular}}Two := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
2016-06-14 15:15:32 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-08-14 10:58:36 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if err = {{$varNameSingular}}Two.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-14 15:15:32 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2016-06-14 15:15:32 +02:00
|
|
|
}
|
2016-07-15 07:32:36 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if count != 2 {
|
|
|
|
t.Error("want 2 records, got:", count)
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|