Convert all tests to go 1.7 Run format
* This fixes postgres deadlocks
This commit is contained in:
parent
7be2f9f2bc
commit
76d4b84019
17 changed files with 184 additions and 25 deletions
|
@ -208,6 +208,11 @@ var defaultSingletonTestTemplateImports = map[string]imports{
|
|||
`"github.com/vattle/sqlboiler/boil"`,
|
||||
},
|
||||
},
|
||||
"boil_test_suite": {
|
||||
standard: importList{
|
||||
`"testing"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var defaultTestMainImports = map[string]imports{
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
var (
|
||||
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
|
||||
uppercaseWords = regexp.MustCompile(`^(?i)(id|uid|uuid|guid|ssn|tz)[0-9]*$`)
|
||||
uppercaseWords = regexp.MustCompile(`^(?i)(id|uid|db|uuid|guid|ssn|tz)[0-9]*$`)
|
||||
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*(\.\*)?$`)
|
||||
)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}(t *testing.T) {
|
||||
func test{{$tableNamePlural}}(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := {{$tableNamePlural}}(nil)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Delete(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -32,7 +32,7 @@ func Test{{$tableNamePlural}}Delete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
|
||||
func test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -62,7 +62,7 @@ func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) {
|
||||
func test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Exists(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Exists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Find(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Find(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Bind(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Bind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -23,7 +23,7 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}One(t *testing.T) {
|
||||
func test{{$tableNamePlural}}One(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -46,7 +46,7 @@ func Test{{$tableNamePlural}}One(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}All(t *testing.T) {
|
||||
func test{{$tableNamePlural}}All(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -79,7 +79,7 @@ func Test{{$tableNamePlural}}All(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}Count(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Count(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
var {{$varNameSingular}}DBTypes = map[string]string{{"{"}}{{.Table.Columns | columnDBTypes | makeStringMap}}{{"}"}}
|
||||
|
||||
func Test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
|
||||
func test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
@ -29,7 +29,7 @@ func Test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
|
|||
{{- end}}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}SliceInPrimaryKeyArgs(t *testing.T) {
|
||||
func test{{$tableNamePlural}}SliceInPrimaryKeyArgs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
|
|
@ -22,8 +22,9 @@ func {{$varNameSingular}}AfterUpdateHook(o *{{$tableNameSingular}}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}Hooks(t *testing.T) {
|
||||
t.Skip("skipping for transactions")
|
||||
func test{{$tableNamePlural}}Hooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
empty := &{{$tableNameSingular}}{}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
{{- $parent := . -}}
|
||||
func Test{{$tableNamePlural}}Insert(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Insert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -29,7 +29,7 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
|
||||
func test{{$tableNamePlural}}InsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{{- template "relationship_to_one_test_helper" (textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table .) -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
||||
func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{- define "relationship_to_one_test_helper"}}
|
||||
func Test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(t *testing.T) {
|
||||
func test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tx := MustTx(boil.Begin())
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Reload(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Reload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -23,7 +23,7 @@ func Test{{$tableNamePlural}}Reload(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}ReloadAll(t *testing.T) {
|
||||
func test{{$tableNamePlural}}ReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Select(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Select(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
153
templates_test/singleton/boil_test_suite.tpl
Normal file
153
templates_test/singleton/boil_test_suite.tpl
Normal file
|
@ -0,0 +1,153 @@
|
|||
// This test suite runs each operation test in parallel.
|
||||
// Example, if your database has 3 tables, the suite will run:
|
||||
// table1, table2 and table3 Delete in parallel
|
||||
// table1, table2 and table3 Insert in parallel, and so forth.
|
||||
// It does NOT run each operation group in parallel.
|
||||
// Separating the tests thusly grants avoidance of Postgres deadlocks.
|
||||
func TestAll(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}})
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Delete)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}QueryDeleteAll)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}SliceDeleteAll)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Exists)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Find)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestFinishers(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Bind)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}One)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}All)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Count)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestHelpers(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}InPrimaryKeyArgs)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}SliceInPrimaryKeyArgs)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Hooks)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Insert)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}InsertWhitelist)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestRelationships(t *testing.T) {
|
||||
{{- $dot := .}}
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- range $table.ToManyRelationships -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $funcName := $rel.LocalTable.NameGo -}}
|
||||
t.Run("{{$rel.ForeignTable.NameGo}}ToOne", test{{$rel.ForeignTable.NameGo}}ToOne{{$rel.LocalTable.NameGo}}_{{$funcName}})
|
||||
{{else -}}
|
||||
t.Run("{{$rel.LocalTable.NameGo}}ToMany", test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}})
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
{{- end -}}{{- /* outer tables range */ -}}
|
||||
}
|
||||
|
||||
func TestReload(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Reload)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}ReloadAll)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Select)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Update)
|
||||
t.Run("{{$tableName}}", test{{$tableName}}SliceUpdateAll)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
||||
|
||||
func TestUpsert(t *testing.T) {
|
||||
{{- range $index, $table := .Tables}}
|
||||
{{- if $table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $tableName := $table.Name | plural | titleCase -}}
|
||||
t.Run("{{$tableName}}", test{{$tableName}}Upsert)
|
||||
{{end -}}
|
||||
{{- end -}}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Update(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Update(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
@ -36,7 +36,7 @@ func Test{{$tableNamePlural}}Update(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test{{$tableNamePlural}}SliceUpdateAll(t *testing.T) {
|
||||
func test{{$tableNamePlural}}SliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
||||
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||
func Test{{$tableNamePlural}}Upsert(t *testing.T) {
|
||||
func test{{$tableNamePlural}}Upsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := boil.NewSeed()
|
||||
|
|
Loading…
Add table
Reference in a new issue