diff --git a/imports.go b/imports.go index 0f1bf7f..677c32b 100644 --- a/imports.go +++ b/imports.go @@ -197,7 +197,9 @@ var defaultSingletonTestTemplateImports = map[string]imports{ `"math/rand"`, `"bytes"`, }, - thirdParty: importList{}, + thirdParty: importList{ + `"github.com/nullbio/sqlboiler/boil"`, + }, }, } diff --git a/templates_test/all.tpl b/templates_test/all.tpl index 86ac7c0..9de1d26 100644 --- a/templates_test/all.tpl +++ b/templates_test/all.tpl @@ -6,9 +6,6 @@ func Test{{$tableNamePlural}}(t *testing.T) { var err error - // Start from a clean slate - {{$varNamePlural}}DeleteAllRows(t) - o := make({{$varNameSingular}}Slice, 2) if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err) @@ -63,4 +60,6 @@ func Test{{$tableNamePlural}}(t *testing.T) { if len(res) != 3 { t.Errorf("Expected 3 {{$tableNameSingular}} rows, got %d", len(res)) } + + {{$varNamePlural}}DeleteAllRows(t) } diff --git a/templates_test/find.tpl b/templates_test/find.tpl index 937cab0..12dfc77 100644 --- a/templates_test/find.tpl +++ b/templates_test/find.tpl @@ -6,8 +6,6 @@ func Test{{$tableNamePlural}}Find(t *testing.T) { var err error - {{$varNamePlural}}DeleteAllRows(t) - o := make({{$varNameSingular}}Slice, 3) if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err) @@ -41,4 +39,6 @@ func Test{{$tableNamePlural}}Find(t *testing.T) { t.Errorf("Expected all other columns to be zero value, but column %s was %#v", v, val.Interface()) } } + + {{$varNamePlural}}DeleteAllRows(t) } diff --git a/templates_test/finishers.tpl b/templates_test/finishers.tpl index a891b38..d193fd9 100644 --- a/templates_test/finishers.tpl +++ b/templates_test/finishers.tpl @@ -6,8 +6,6 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) { var err error - {{$varNamePlural}}DeleteAllRows(t) - o := {{$tableNameSingular}}{} if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) @@ -55,13 +53,13 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) { for i := 0; i < len(y); i++ { {{$varNameSingular}}CompareVals(y[i], k[i], t) } + + {{$varNamePlural}}DeleteAllRows(t) } func Test{{$tableNamePlural}}One(t *testing.T) { var err error - {{$varNamePlural}}DeleteAllRows(t) - o := {{$tableNameSingular}}{} if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) @@ -77,13 +75,13 @@ func Test{{$tableNamePlural}}One(t *testing.T) { } {{$varNameSingular}}CompareVals(&o, j, t) + + {{$varNamePlural}}DeleteAllRows(t) } func Test{{$tableNamePlural}}All(t *testing.T) { var err error - {{$varNamePlural}}DeleteAllRows(t) - o := make({{$varNameSingular}}Slice, 3) if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err) @@ -109,13 +107,13 @@ func Test{{$tableNamePlural}}All(t *testing.T) { for i := 0; i < len(o); i++ { {{$varNameSingular}}CompareVals(o[i], j[i], t) } + + {{$varNamePlural}}DeleteAllRows(t) } func Test{{$tableNamePlural}}Count(t *testing.T) { var err error - {{$varNamePlural}}DeleteAllRows(t) - o := make({{$varNameSingular}}Slice, 3) if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err) @@ -137,4 +135,6 @@ func Test{{$tableNamePlural}}Count(t *testing.T) { if c != 3 { t.Errorf("Expected 3 results from count {{$tableNameSingular}}, got %d", c) } + + {{$varNamePlural}}DeleteAllRows(t) } diff --git a/templates_test/insert.tpl b/templates_test/insert.tpl index ce72173..ad99e7a 100644 --- a/templates_test/insert.tpl +++ b/templates_test/insert.tpl @@ -16,8 +16,6 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) { nullTime := null.NewTime(time.Time{}, true) _ = nullTime - {{$varNamePlural}}DeleteAllRows(t) - o := make({{$varNameSingular}}Slice, 3) if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil { t.Errorf("Unable to randomize {{$tableNameSingular}} slice: %s", err) @@ -105,4 +103,6 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) { if !reflect.DeepEqual(wl, {{$varNameSingular}}Columns) { t.Errorf("Expected whitelist to contain all columns values:\n\nGot: %v\nWanted: %v", wl, {{$varNameSingular}}Columns) } + + {{$varNamePlural}}DeleteAllRows(t) } diff --git a/templates_test/singleton/helper_funcs.tpl b/templates_test/singleton/helper_funcs.tpl index 410d7db..e23874a 100644 --- a/templates_test/singleton/helper_funcs.tpl +++ b/templates_test/singleton/helper_funcs.tpl @@ -1,5 +1,12 @@ var dbNameRand *rand.Rand +func MustTx(transactor boil.Transactor, err error) boil.Transactor { + if err != nil { + panic(fmt.Sprintf("Cannot create a transactor: %s", err)) + } + return transactor +} + func initDBNameRand(input string) { sum := md5.Sum([]byte(input))