Make all tests create random seed and use MustTx

- Mark Upsert/Find for parallelism
This commit is contained in:
Aaron L 2016-08-14 20:14:39 -07:00
parent 490cdef5bc
commit 6f963d518c
12 changed files with 89 additions and 118 deletions

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Delete(t *testing.T) { func Test{{$tableNamePlural}}Delete(t *testing.T) {
t.Parallel() t.Parallel()
tx, err := boil.Begin() seed := new(boil.Seed)
if err != nil { var err error
t.Fatal(err)
}
defer tx.Rollback()
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx := MustTx(boil.Begin())
defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -37,17 +35,15 @@ func Test{{$tableNamePlural}}Delete(t *testing.T) {
func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) { func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
t.Parallel() t.Parallel()
tx, err := boil.Begin() seed := new(boil.Seed)
if err != nil { var err error
t.Fatal(err)
}
defer tx.Rollback()
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx := MustTx(boil.Begin())
defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -69,17 +65,15 @@ func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
func Test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) { func Test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) {
t.Parallel() t.Parallel()
tx, err := boil.Begin() seed := new(boil.Seed)
if err != nil { var err error
t.Fatal(err)
}
defer tx.Rollback()
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx := MustTx(boil.Begin())
defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Exists(t *testing.T) { func Test{{$tableNamePlural}}Exists(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -3,17 +3,17 @@
{{- $varNamePlural := .Table.Name | plural | camelCase -}} {{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
func Test{{$tableNamePlural}}Find(t *testing.T) { func Test{{$tableNamePlural}}Find(t *testing.T) {
t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Bind(t *testing.T) { func Test{{$tableNamePlural}}Bind(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -28,17 +26,15 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
func Test{{$tableNamePlural}}One(t *testing.T) { func Test{{$tableNamePlural}}One(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -53,21 +49,19 @@ func Test{{$tableNamePlural}}One(t *testing.T) {
func Test{{$tableNamePlural}}All(t *testing.T) { func Test{{$tableNamePlural}}All(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}}One := &{{$tableNameSingular}}{} {{$varNameSingular}}One := &{{$tableNameSingular}}{}
{{$varNameSingular}}Two := &{{$tableNameSingular}}{} {{$varNameSingular}}Two := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
if err := boil.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}One.Insert(tx); err != nil { if err = {{$varNameSingular}}One.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -88,21 +82,19 @@ func Test{{$tableNamePlural}}All(t *testing.T) {
func Test{{$tableNamePlural}}Count(t *testing.T) { func Test{{$tableNamePlural}}Count(t *testing.T) {
t.Parallel() t.Parallel()
var err error
seed := new(boil.Seed)
{{$varNameSingular}}One := &{{$tableNameSingular}}{} {{$varNameSingular}}One := &{{$tableNameSingular}}{}
{{$varNameSingular}}Two := &{{$tableNameSingular}}{} {{$varNameSingular}}Two := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}One, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
if err := boil.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}Two, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}One.Insert(tx); err != nil { if err = {{$varNameSingular}}One.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -11,7 +11,8 @@ func Test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
var o {{$tableNameSingular}} var o {{$tableNameSingular}}
o = {{$tableNameSingular}}{} o = {{$tableNameSingular}}{}
if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes, true); err != nil { seed := new(boil.Seed)
if err = seed.RandomizeStruct(&o, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Could not randomize struct: %s", err) t.Errorf("Could not randomize struct: %s", err)
} }
@ -34,9 +35,10 @@ func Test{{$tableNamePlural}}SliceInPrimaryKeyArgs(t *testing.T) {
var err error var err error
o := make({{$tableNameSingular}}Slice, 3) o := make({{$tableNameSingular}}Slice, 3)
seed := new(boil.Seed)
for i := range o { for i := range o {
o[i] = &{{$tableNameSingular}}{} o[i] = &{{$tableNameSingular}}{}
if err = boil.RandomizeStruct(o[i], {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct(o[i], {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Could not randomize struct: %s", err) t.Errorf("Could not randomize struct: %s", err)
} }
} }

View file

@ -29,7 +29,8 @@ func Test{{$tableNamePlural}}Hooks(t *testing.T) {
empty := &{{$tableNameSingular}}{} empty := &{{$tableNameSingular}}{}
o := &{{$tableNameSingular}}{} o := &{{$tableNameSingular}}{}
if err = boil.RandomizeStruct(o, {{$varNameSingular}}DBTypes, false); err != nil { seed := new(boil.Seed)
if err = seed.RandomizeStruct(o, {{$varNameSingular}}DBTypes, false); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err)
} }

View file

@ -6,17 +6,15 @@
func Test{{$tableNamePlural}}Insert(t *testing.T) { func Test{{$tableNamePlural}}Insert(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -34,17 +32,15 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) {
func Test{{$tableNamePlural}}InsertWhitelist(t *testing.T) { func Test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx, {{$varNameSingular}}Columns...); err != nil { if err = {{$varNameSingular}}.Insert(tx, {{$varNameSingular}}Columns...); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -21,8 +21,9 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
boil.RandomizeStruct(&b, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, false, "{{.ForeignColumn}}") seed := new(boil.Seed)
boil.RandomizeStruct(&c, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, false, "{{.ForeignColumn}}") seed.RandomizeStruct(&b, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, false, "{{.ForeignColumn}}")
seed.RandomizeStruct(&c, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, false, "{{.ForeignColumn}}")
{{if .Nullable -}} {{if .Nullable -}}
a.{{.Column | titleCase}}.Valid = true a.{{.Column | titleCase}}.Valid = true
{{- end}} {{- end}}

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Reload(t *testing.T) { func Test{{$tableNamePlural}}Reload(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -28,17 +26,15 @@ func Test{{$tableNamePlural}}Reload(t *testing.T) {
func Test{{$tableNamePlural}}ReloadAll(t *testing.T) { func Test{{$tableNamePlural}}ReloadAll(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Select(t *testing.T) { func Test{{$tableNamePlural}}Select(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }

View file

@ -5,17 +5,15 @@
func Test{{$tableNamePlural}}Update(t *testing.T) { func Test{{$tableNamePlural}}Update(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -29,7 +27,7 @@ func Test{{$tableNamePlural}}Update(t *testing.T) {
t.Error("want one record, got:", count) t.Error("want one record, got:", count)
} }
if err = boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}PrimaryKeyColumns...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}PrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
@ -41,17 +39,15 @@ func Test{{$tableNamePlural}}Update(t *testing.T) {
func Test{{$tableNamePlural}}SliceUpdateAll(t *testing.T) { func Test{{$tableNamePlural}}SliceUpdateAll(t *testing.T) {
t.Parallel() t.Parallel()
seed := new(boil.Seed)
var err error
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
if err := boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Insert(tx); err != nil { if err = {{$varNameSingular}}.Insert(tx); err != nil {
t.Error(err) t.Error(err)
} }
@ -65,7 +61,7 @@ func Test{{$tableNamePlural}}SliceUpdateAll(t *testing.T) {
t.Error("want one record, got:", count) t.Error("want one record, got:", count)
} }
if err = boil.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}PrimaryKeyColumns...); err != nil { if err = seed.RandomizeStruct({{$varNameSingular}}, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}PrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }

View file

@ -3,21 +3,18 @@
{{- $varNamePlural := .Table.Name | plural | camelCase -}} {{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
func Test{{$tableNamePlural}}Upsert(t *testing.T) { func Test{{$tableNamePlural}}Upsert(t *testing.T) {
t.Parallel()
seed := new(boil.Seed)
var err error var err error
{{$varNameSingular}} := {{$tableNameSingular}}{}
// Attempt the INSERT side of an UPSERT // Attempt the INSERT side of an UPSERT
if err = boil.RandomizeStruct(&{{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil { {{$varNameSingular}} := {{$tableNameSingular}}{}
if err = seed.RandomizeStruct(&{{$varNameSingular}}, {{$varNameSingular}}DBTypes, true); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
tx, err := boil.Begin() tx := MustTx(boil.Begin())
if err != nil {
t.Fatal(err)
}
defer tx.Rollback() defer tx.Rollback()
if err = {{$varNameSingular}}.Upsert(tx, false, nil, nil); err != nil { if err = {{$varNameSingular}}.Upsert(tx, false, nil, nil); err != nil {
t.Errorf("Unable to upsert {{$tableNameSingular}}: %s", err) t.Errorf("Unable to upsert {{$tableNameSingular}}: %s", err)
} }
@ -31,7 +28,7 @@ func Test{{$tableNamePlural}}Upsert(t *testing.T) {
} }
// Attempt the UPDATE side of an UPSERT // Attempt the UPDATE side of an UPSERT
if err = boil.RandomizeStruct(&{{$varNameSingular}}, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}PrimaryKeyColumns...); err != nil { if err = seed.RandomizeStruct(&{{$varNameSingular}}, {{$varNameSingular}}DBTypes, false, {{$varNameSingular}}PrimaryKeyColumns...); err != nil {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }