mirror of
https://github.com/pressly/goose.git
synced 2025-05-25 17:01:18 +00:00
Make tests more readable
This commit is contained in:
parent
e60424535d
commit
f81c971ff2
@ -9,7 +9,6 @@ func newMigration(v int64, src string) *Migration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrationSort(t *testing.T) {
|
func TestMigrationSort(t *testing.T) {
|
||||||
|
|
||||||
ms := Migrations{}
|
ms := Migrations{}
|
||||||
|
|
||||||
// insert in any order
|
// insert in any order
|
||||||
@ -26,7 +25,6 @@ func TestMigrationSort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
|
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
|
||||||
|
|
||||||
for i, m := range ms {
|
for i, m := range ms {
|
||||||
if sorted[i] != m.Version {
|
if sorted[i] != m.Version {
|
||||||
t.Error("incorrect sorted version")
|
t.Error("incorrect sorted version")
|
||||||
|
@ -7,37 +7,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSemicolons(t *testing.T) {
|
func TestSemicolons(t *testing.T) {
|
||||||
|
|
||||||
type testData struct {
|
type testData struct {
|
||||||
line string
|
line string
|
||||||
result bool
|
result bool
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []testData{
|
tests := []testData{
|
||||||
{
|
{line: "END;", result: true},
|
||||||
line: "END;",
|
{line: "END; -- comment", result: true},
|
||||||
result: true,
|
{line: "END ; -- comment", result: true},
|
||||||
},
|
{line: "END -- comment", result: false},
|
||||||
{
|
{line: "END -- comment ;", result: false},
|
||||||
line: "END; -- comment",
|
{line: "END \" ; \" -- comment", result: false},
|
||||||
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 {
|
for _, test := range tests {
|
||||||
@ -49,7 +30,6 @@ func TestSemicolons(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSplitStatements(t *testing.T) {
|
func TestSplitStatements(t *testing.T) {
|
||||||
|
|
||||||
type testData struct {
|
type testData struct {
|
||||||
sql string
|
sql string
|
||||||
direction bool
|
direction bool
|
||||||
@ -57,26 +37,10 @@ func TestSplitStatements(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []testData{
|
tests := []testData{
|
||||||
{
|
{sql: functxt, direction: true, count: 2},
|
||||||
sql: functxt,
|
{sql: functxt, direction: false, count: 2},
|
||||||
direction: true,
|
{sql: multitxt, direction: true, count: 2},
|
||||||
count: 2,
|
{sql: multitxt, direction: false, count: 2},
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: functxt,
|
|
||||||
direction: false,
|
|
||||||
count: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: multitxt,
|
|
||||||
direction: true,
|
|
||||||
count: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: multitxt,
|
|
||||||
direction: false,
|
|
||||||
count: 2,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -97,18 +61,9 @@ func TestUseTransactions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []testData{
|
tests := []testData{
|
||||||
{
|
{fileName: "./examples/sql-migrations/00001_create_users_table.sql", useTransactions: true},
|
||||||
fileName: "./examples/sql-migrations/00001_create_users_table.sql",
|
{fileName: "./examples/sql-migrations/00002_rename_root.sql", useTransactions: true},
|
||||||
useTransactions: true,
|
{fileName: "./examples/sql-migrations/00003_no_transaction.sql", useTransactions: false},
|
||||||
},
|
|
||||||
{
|
|
||||||
fileName: "./examples/sql-migrations/00002_rename_root.sql",
|
|
||||||
useTransactions: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fileName: "./examples/sql-migrations/00003_no_transaction.sql",
|
|
||||||
useTransactions: false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -133,18 +88,9 @@ func TestParsingErrors(t *testing.T) {
|
|||||||
error bool
|
error bool
|
||||||
}
|
}
|
||||||
tests := []testData{
|
tests := []testData{
|
||||||
{
|
{sql: statementBeginNoStatementEnd, error: true},
|
||||||
sql: statementBeginNoStatementEnd,
|
{sql: unfinishedSQL, error: true},
|
||||||
error: true,
|
{sql: noUpDownAnnotations, error: true},
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: unfinishedSQL,
|
|
||||||
error: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: noUpDownAnnotations,
|
|
||||||
error: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
_, _, err := getSQLStatements(strings.NewReader(test.sql), true)
|
_, _, err := getSQLStatements(strings.NewReader(test.sql), true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user