sqlboiler/templates_test/exists.tpl

30 lines
1.1 KiB
Smarty
Raw Normal View History

2016-08-03 12:23:43 +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}}Exists(t *testing.T) {
2016-08-14 10:58:36 +02:00
t.Parallel()
2016-08-03 12:23:43 +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-03 12:23:43 +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-03 12:23:43 +02:00
}
2016-08-14 10:58:36 +02:00
{{$pkeyArgs := .Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice (printf "%s." $varNameSingular) | join ", " -}}
e, err := {{$tableNameSingular}}Exists(tx, {{$pkeyArgs}})
2016-08-03 12:23:43 +02:00
if err != nil {
t.Errorf("Unable to check if {{$tableNameSingular}} exists: %s", err)
}
2016-08-14 10:58:36 +02:00
if e != true {
t.Errorf("Expected {{$tableNameSingular}}ExistsG to return true, but got false.")
2016-08-03 12:23:43 +02:00
}
}