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 -}}
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Exists(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
2016-08-03 12:23:43 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
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)
|
|
|
|
}
|
2016-08-03 12:23:43 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-08-03 12:23:43 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
{{$pkeyArgs := .Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice (printf "%s." $varNameSingular) | join ", " -}}
|
|
|
|
e, err := {{$tableNameSingular}}Exists(tx, {{$pkeyArgs}})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to check if {{$tableNameSingular}} exists: %s", err)
|
|
|
|
}
|
2016-09-21 00:35:03 +02:00
|
|
|
if !e {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Errorf("Expected {{$tableNameSingular}}ExistsG to return true, but got false.")
|
|
|
|
}
|
2016-08-03 12:23:43 +02:00
|
|
|
}
|