From f81c971ff2329fda601db75d310d35e242e0c106 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Mon, 4 Mar 2019 21:27:22 -0500 Subject: [PATCH] Make tests more readable --- migrate_test.go | 2 - migration_sql_test.go | 86 ++++++++----------------------------------- 2 files changed, 16 insertions(+), 72 deletions(-) diff --git a/migrate_test.go b/migrate_test.go index c14f6b5..e1b5802 100644 --- a/migrate_test.go +++ b/migrate_test.go @@ -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") diff --git a/migration_sql_test.go b/migration_sql_test.go index a12a828..07a20e7 100644 --- a/migration_sql_test.go +++ b/migration_sql_test.go @@ -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)