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-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Insert(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
var err error
|
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if count != 1 {
|
|
|
|
t.Error("want one record, got:", count)
|
|
|
|
}
|
2016-08-14 08:38:41 +02:00
|
|
|
}
|
2016-07-06 08:02:35 +02:00
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
var err error
|
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2017-03-16 07:55:50 +01:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx, {{$varNameSingular}}ColumnsWithoutDefault...); err != nil {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if count != 1 {
|
|
|
|
t.Error("want one record, got:", count)
|
|
|
|
}
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|