sqlboiler/templates_test/insert.tpl

57 lines
1.6 KiB
Smarty
Raw Normal View History

{{- $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 := . -}}
func test{{$tableNamePlural}}Insert(t *testing.T) {
2016-08-14 10:58:36 +02:00
t.Parallel()
2016-08-18 09:06:28 +02:00
seed := randomize.NewSeed()
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{}
2016-08-18 09:06:28 +02:00
if err = randomize.Struct(seed, {{$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)
}
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)
}
}
func test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
2016-08-14 10:58:36 +02:00
t.Parallel()
2016-08-18 09:06:28 +02:00
seed := randomize.NewSeed()
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{}
2016-08-18 09:06:28 +02:00
if err = randomize.Struct(seed, {{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
2016-08-14 11:11:32 +02:00
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
}
tx := MustTx(boil.Begin())
defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx, {{$varNameSingular}}Columns...); 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)
}
}