2016-07-06 08:02:35 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-07-09 18:31:09 +02:00
|
|
|
{{- $parent := . -}}
|
2016-07-06 08:02:35 +02:00
|
|
|
func Test{{$tableNamePlural}}Insert(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
|
|
|
if err := boil.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-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 06:21:26 +02:00
|
|
|
tx, err := boil.Begin()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-08-14 08:38:41 +02:00
|
|
|
defer tx.Rollback()
|
2016-08-14 06:21:26 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
2016-08-14 06:21:26 +02:00
|
|
|
if err != nil {
|
2016-08-14 08:38:41 +02:00
|
|
|
t.Error(err)
|
2016-08-14 06:21:26 +02:00
|
|
|
}
|
2016-07-07 17:59:07 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
if count != 1 {
|
|
|
|
t.Error("want one record, got:", count)
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
2016-08-14 08:38:41 +02:00
|
|
|
}
|
2016-07-06 08:02:35 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
func Test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
|
|
|
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
tx, err := boil.Begin()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-07-08 18:39:36 +02:00
|
|
|
}
|
2016-08-14 08:38:41 +02:00
|
|
|
defer tx.Rollback()
|
2016-07-08 18:39:36 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx, {{$varNameSingular}}Columns...); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-07-14 06:12:26 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-07-14 06:12:26 +02:00
|
|
|
|
2016-08-14 08:38:41 +02:00
|
|
|
if count != 1 {
|
|
|
|
t.Error("want one record, got:", count)
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
}
|