Make tests more readable

pull/151/head
Vojtech Vitek 2019-03-04 21:27:22 -05:00
parent e60424535d
commit f81c971ff2
2 changed files with 16 additions and 72 deletions

View File

@ -9,7 +9,6 @@ func newMigration(v int64, src string) *Migration {
}
func TestMigrationSort(t *testing.T) {
ms := Migrations{}
// insert in any order
@ -26,7 +25,6 @@ func TestMigrationSort(t *testing.T) {
}
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
for i, m := range ms {
if sorted[i] != m.Version {
t.Error("incorrect sorted version")

View File

@ -7,37 +7,18 @@ import (
)
func TestSemicolons(t *testing.T) {
type testData struct {
line string
result bool
}
tests := []testData{
{
line: "END;",
result: true,
},
{
line: "END; -- comment",
result: true,
},
{
line: "END ; -- comment",
result: true,
},
{
line: "END -- comment",
result: false,
},
{
line: "END -- comment ;",
result: false,
},
{
line: "END \" ; \" -- comment",
result: false,
},
{line: "END;", result: true},
{line: "END; -- comment", result: true},
{line: "END ; -- comment", result: true},
{line: "END -- comment", result: false},
{line: "END -- comment ;", result: false},
{line: "END \" ; \" -- comment", result: false},
}
for _, test := range tests {
@ -49,7 +30,6 @@ func TestSemicolons(t *testing.T) {
}
func TestSplitStatements(t *testing.T) {
type testData struct {
sql string
direction bool
@ -57,26 +37,10 @@ func TestSplitStatements(t *testing.T) {
}
tests := []testData{
{
sql: functxt,
direction: true,
count: 2,
},
{
sql: functxt,
direction: false,
count: 2,
},
{
sql: multitxt,
direction: true,
count: 2,
},
{
sql: multitxt,
direction: false,
count: 2,
},
{sql: functxt, direction: true, count: 2},
{sql: functxt, direction: false, count: 2},
{sql: multitxt, direction: true, count: 2},
{sql: multitxt, direction: false, count: 2},
}
for _, test := range tests {
@ -97,18 +61,9 @@ func TestUseTransactions(t *testing.T) {
}
tests := []testData{
{
fileName: "./examples/sql-migrations/00001_create_users_table.sql",
useTransactions: true,
},
{
fileName: "./examples/sql-migrations/00002_rename_root.sql",
useTransactions: true,
},
{
fileName: "./examples/sql-migrations/00003_no_transaction.sql",
useTransactions: false,
},
{fileName: "./examples/sql-migrations/00001_create_users_table.sql", useTransactions: true},
{fileName: "./examples/sql-migrations/00002_rename_root.sql", useTransactions: true},
{fileName: "./examples/sql-migrations/00003_no_transaction.sql", useTransactions: false},
}
for _, test := range tests {
@ -133,18 +88,9 @@ func TestParsingErrors(t *testing.T) {
error bool
}
tests := []testData{
{
sql: statementBeginNoStatementEnd,
error: true,
},
{
sql: unfinishedSQL,
error: true,
},
{
sql: noUpDownAnnotations,
error: true,
},
{sql: statementBeginNoStatementEnd, error: true},
{sql: unfinishedSQL, error: true},
{sql: noUpDownAnnotations, error: true},
}
for _, test := range tests {
_, _, err := getSQLStatements(strings.NewReader(test.sql), true)