sqlboiler/templates_test/hooks.tpl
Patrick O'brien 76d4b84019 Convert all tests to go 1.7 Run format
* This fixes postgres deadlocks
2016-08-15 19:36:38 +10:00

47 lines
1.5 KiB
Smarty

{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func {{$varNameSingular}}BeforeCreateHook(o *{{$tableNameSingular}}) error {
*o = {{$tableNameSingular}}{}
return nil
}
func {{$varNameSingular}}AfterCreateHook(o *{{$tableNameSingular}}) error {
*o = {{$tableNameSingular}}{}
return nil
}
func {{$varNameSingular}}BeforeUpdateHook(o *{{$tableNameSingular}}) error {
*o = {{$tableNameSingular}}{}
return nil
}
func {{$varNameSingular}}AfterUpdateHook(o *{{$tableNameSingular}}) error {
*o = {{$tableNameSingular}}{}
return nil
}
func test{{$tableNamePlural}}Hooks(t *testing.T) {
t.Parallel()
var err error
empty := &{{$tableNameSingular}}{}
o := &{{$tableNameSingular}}{}
seed := boil.NewSeed()
if err = seed.RandomizeStruct(o, {{$varNameSingular}}DBTypes, false); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err)
}
{{$tableNameSingular}}AddHook(boil.HookBeforeCreate, {{$varNameSingular}}BeforeCreateHook)
if err = o.doBeforeCreateHooks(); err != nil {
t.Errorf("Unable to execute doBeforeCreateHooks: %s", err)
}
if !reflect.DeepEqual(o, empty) {
t.Errorf("Expected BeforeCreateHook function to empty object, but got: %#v", o)
}
{{$varNameSingular}}BeforeCreateHooks = []{{$tableNameSingular}}Hook{}
}