sqlboiler/templates_test/reload.tpl

48 lines
1.5 KiB
Smarty
Raw Normal View History

2016-08-02 11:56:55 +02:00
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func test{{$tableNamePlural}}Reload(t *testing.T) {
2016-08-14 10:58:36 +02:00
t.Parallel()
2016-08-02 11:56:55 +02:00
2016-08-18 09:06:28 +02:00
seed := randomize.NewSeed()
var err error
2016-08-14 10:58:36 +02:00
{{$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)
2016-08-02 11:56:55 +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-08-02 11:56:55 +02:00
}
2016-08-14 10:58:36 +02:00
if err = {{$varNameSingular}}.Reload(tx); err != nil {
t.Error(err)
}
2016-08-02 11:56:55 +02:00
}
func test{{$tableNamePlural}}ReloadAll(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
2016-08-14 10:58:36 +02:00
{{$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())
2016-08-14 10:58:36 +02:00
defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err)
}
2016-08-14 10:58:36 +02:00
slice := {{$tableNameSingular}}Slice{{"{"}}{{$varNameSingular}}{{"}"}}
2016-08-14 10:58:36 +02:00
if err = slice.ReloadAll(tx); err != nil {
t.Error(err)
}
}