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-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Bind(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = {{$tableNamePlural}}(tx).Bind({{$varNameSingular}}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}One(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if x, err := {{$tableNamePlural}}(tx).One(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
} else if x == nil {
|
|
|
|
t.Error("expected to get a non nil record")
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}All(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
var err error
|
|
|
|
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
|
|
|
|
{{$varNameSingular}}Two := &{{$tableNameSingular}}{}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if err = {{$varNameSingular}}Two.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
slice, err := {{$tableNamePlural}}(tx).All()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(slice) != 2 {
|
|
|
|
t.Error("want 2 records, got:", len(slice))
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Count(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
|
|
|
|
{{$varNameSingular}}Two := &{{$tableNameSingular}}{}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
2016-12-20 04:29:11 +01:00
|
|
|
count, err := {{$tableNamePlural}}(tx).Count()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if count != 0 {
|
|
|
|
t.Error("want 0 records found")
|
|
|
|
}
|
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if err = {{$varNameSingular}}Two.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2016-12-20 04:29:11 +01:00
|
|
|
count, err = {{$tableNamePlural}}(tx).Count()
|
2016-09-14 10:08:30 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if count != 2 {
|
|
|
|
t.Error("want 2 records, got:", count)
|
|
|
|
}
|
2016-06-10 16:22:08 +02:00
|
|
|
}
|
2016-12-20 04:29:11 +01:00
|
|
|
|
|
|
|
func test{{$tableNamePlural}}ExistsFinisher(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
{{$varNameSingular}}One := &{{$tableNameSingular}}{}
|
|
|
|
if err = randomize.Struct(seed, {{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := MustTx(boil.Begin())
|
|
|
|
defer tx.Rollback()
|
|
|
|
exists, err := {{$tableNamePlural}}(tx).Exists()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
t.Error("the record should not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = {{$varNameSingular}}One.Insert(tx); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
exists, err = {{$tableNamePlural}}(tx).Exists()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
|
|
|
t.Error("wanted record to exist")
|
|
|
|
}
|
|
|
|
}
|