2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-14 10:58:36 +02:00
|
|
|
func Test{{$tableNamePlural}}Delete(t *testing.T) {
|
|
|
|
t.Parallel()
|
2016-06-08 07:45:34 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
seed := new(boil.Seed)
|
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 06:40:02 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$varNameSingular}}.Delete(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-08 07:45:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
2016-06-08 07:45:34 +02:00
|
|
|
if err != nil {
|
2016-08-14 10:58:36 +02:00
|
|
|
t.Error(err)
|
2016-06-08 07:45:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if count != 0 {
|
|
|
|
t.Error("want zero records, got:", count)
|
2016-06-08 07:45:34 +02:00
|
|
|
}
|
2016-06-10 07:38:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
|
|
|
|
t.Parallel()
|
2016-06-08 07:45:34 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
seed := new(boil.Seed)
|
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 04:09:48 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$tableNamePlural}}(tx).DeleteAll(); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 07:20:26 +02:00
|
|
|
}
|
2016-06-10 04:09:48 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-06-10 04:09:48 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if count != 0 {
|
|
|
|
t.Error("want zero records, got:", count)
|
2016-06-10 04:09:48 +02:00
|
|
|
}
|
2016-06-10 07:38:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
func Test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) {
|
|
|
|
t.Parallel()
|
2016-06-10 04:09:48 +02:00
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
seed := new(boil.Seed)
|
|
|
|
var err error
|
2016-08-14 10:58:36 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-08-15 05:14:39 +02:00
|
|
|
if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-08-14 11:11:32 +02:00
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-08-15 05:14:39 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-08 07:45:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
slice := {{$tableNameSingular}}Slice{{"{"}}{{$varNameSingular}}{{"}"}}
|
2016-06-10 04:09:48 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if err = slice.DeleteAll(tx); err != nil {
|
|
|
|
t.Error(err)
|
2016-06-10 04:09:48 +02:00
|
|
|
}
|
2016-06-10 07:38:58 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-06-10 07:38:58 +02:00
|
|
|
|
2016-08-14 10:58:36 +02:00
|
|
|
if count != 0 {
|
|
|
|
t.Error("want zero records, got:", count)
|
2016-06-10 07:38:58 +02:00
|
|
|
}
|
2016-06-08 07:45:34 +02:00
|
|
|
}
|