Skip to content

Commit e1b59f5

Browse files
committed
Fix tests & run them all in parallel
1 parent 8c4336a commit e1b59f5

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

fix_test.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ import (
1111
)
1212

1313
func TestFix(t *testing.T) {
14+
t.Parallel()
15+
1416
dir, err := ioutil.TempDir("", "tmptest")
1517
if err != nil {
1618
t.Fatal(err)
1719
}
1820

19-
defer os.RemoveAll(dir) // clean up
20-
defer os.Remove("goose") // clean up
21+
defer os.RemoveAll(dir) // clean up
22+
defer os.Remove("./bin/fix-goose") // clean up
2123

2224
commands := []string{
23-
"go build -i -o ./bin/goose ./cmd/goose",
24-
fmt.Sprintf("./bin/goose -dir=%s create create_table", dir),
25-
fmt.Sprintf("./bin/goose -dir=%s create add_users", dir),
26-
fmt.Sprintf("./bin/goose -dir=%s create add_indices", dir),
27-
fmt.Sprintf("./bin/goose -dir=%s create update_users", dir),
28-
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
25+
"go build -i -o ./bin/fix-goose ./cmd/goose",
26+
fmt.Sprintf("./bin/fix-goose -dir=%s create create_table", dir),
27+
fmt.Sprintf("./bin/fix-goose -dir=%s create add_users", dir),
28+
fmt.Sprintf("./bin/fix-goose -dir=%s create add_indices", dir),
29+
fmt.Sprintf("./bin/fix-goose -dir=%s create update_users", dir),
30+
fmt.Sprintf("./bin/fix-goose -dir=%s fix", dir),
2931
}
3032

3133
for _, cmd := range commands {
3234
args := strings.Split(cmd, " ")
3335
time.Sleep(1 * time.Second)
34-
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
36+
cmd := exec.Command(args[0], args[1:]...)
37+
cmd.Env = os.Environ()
38+
out, err := cmd.CombinedOutput()
3539
if err != nil {
3640
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
3741
}
@@ -52,9 +56,9 @@ func TestFix(t *testing.T) {
5256

5357
// add more migrations and then fix it
5458
commands = []string{
55-
fmt.Sprintf("./bin/goose -dir=%s create remove_column", dir),
56-
fmt.Sprintf("./bin/goose -dir=%s create create_books_table", dir),
57-
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
59+
fmt.Sprintf("./bin/fix-goose -dir=%s create remove_column", dir),
60+
fmt.Sprintf("./bin/fix-goose -dir=%s create create_books_table", dir),
61+
fmt.Sprintf("./bin/fix-goose -dir=%s fix", dir),
5862
}
5963

6064
for _, cmd := range commands {

goose_test.go

+22-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
)
1111

1212
func TestDefaultBinary(t *testing.T) {
13+
t.Parallel()
14+
1315
commands := []string{
1416
"go build -i -o ./bin/goose ./cmd/goose",
1517
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db up",
@@ -18,6 +20,7 @@ func TestDefaultBinary(t *testing.T) {
1820
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db status",
1921
"./bin/goose",
2022
}
23+
defer os.Remove("./bin/goose") // clean up
2124

2225
for _, cmd := range commands {
2326
args := strings.Split(cmd, " ")
@@ -27,45 +30,53 @@ func TestDefaultBinary(t *testing.T) {
2730
params = args[1:]
2831
}
2932

30-
out, err := exec.Command(command, params...).CombinedOutput()
33+
cmd := exec.Command(command, params...)
34+
cmd.Env = os.Environ()
35+
out, err := cmd.CombinedOutput()
3136
if err != nil {
3237
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
3338
}
3439
}
3540
}
3641

3742
func TestLiteBinary(t *testing.T) {
43+
t.Parallel()
44+
3845
dir, err := ioutil.TempDir("", "tmptest")
3946
if err != nil {
4047
t.Fatal(err)
4148
}
4249

43-
defer os.RemoveAll(dir) // clean up
44-
defer os.Remove("./bin/goose") // clean up
45-
46-
commands := []string{
47-
fmt.Sprintf("./bin/goose -dir=%s create user_indices sql", dir),
48-
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
49-
}
50+
defer os.RemoveAll(dir) // clean up
51+
defer os.Remove("./bin/light-goose") // clean up
5052

5153
// this has to be done outside of the loop
5254
// since go only supports space separated tags list.
53-
cmd := "go build -tags='no_mysql no_sqlite no_psql' -i -o ./bin/goose ./cmd/goose"
54-
out, err := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-i", "-o", "./bin/goose", "./cmd/goose").CombinedOutput()
55+
cmd := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-i", "-o", "./bin/light-goose", "./cmd/goose")
56+
out, err := cmd.CombinedOutput()
5557
if err != nil {
5658
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
5759
}
5860

61+
commands := []string{
62+
fmt.Sprintf("./bin/light-goose -dir=%s create user_indices sql", dir),
63+
fmt.Sprintf("./bin/light-goose -dir=%s fix", dir),
64+
}
65+
5966
for _, cmd := range commands {
6067
args := strings.Split(cmd, " ")
61-
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
68+
cmd := exec.Command(args[0], args[1:]...)
69+
cmd.Env = os.Environ()
70+
out, err := cmd.CombinedOutput()
6271
if err != nil {
6372
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
6473
}
6574
}
6675
}
6776

6877
func TestCustomBinary(t *testing.T) {
78+
t.Parallel()
79+
6980
commands := []string{
7081
"go build -i -o ./bin/custom-goose ./examples/go-migrations",
7182
"./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db up",

helpers_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
)
66

77
func TestCamelSnake(t *testing.T) {
8+
t.Parallel()
9+
810
tt := []struct {
911
in string
1012
camel string

migrate_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"testing"
55
)
66

7-
func newMigration(v int64, src string) *Migration {
8-
return &Migration{Version: v, Previous: -1, Next: -1, Source: src}
9-
}
10-
117
func TestMigrationSort(t *testing.T) {
8+
t.Parallel()
9+
1210
ms := Migrations{}
1311

1412
// insert in any order
@@ -24,6 +22,10 @@ func TestMigrationSort(t *testing.T) {
2422
validateMigrationSort(t, ms, sorted)
2523
}
2624

25+
func newMigration(v int64, src string) *Migration {
26+
return &Migration{Version: v, Previous: -1, Next: -1, Source: src}
27+
}
28+
2729
func validateMigrationSort(t *testing.T, ms Migrations, sorted []int64) {
2830
for i, m := range ms {
2931
if sorted[i] != m.Version {

sql_parser_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestSemicolons(t *testing.T) {
12+
t.Parallel()
13+
1214
type testData struct {
1315
line string
1416
result bool
@@ -32,6 +34,7 @@ func TestSemicolons(t *testing.T) {
3234
}
3335

3436
func TestSplitStatements(t *testing.T) {
37+
t.Parallel()
3538
// SetVerbose(true)
3639

3740
type testData struct {
@@ -72,6 +75,8 @@ func TestSplitStatements(t *testing.T) {
7275
}
7376

7477
func TestUseTransactions(t *testing.T) {
78+
t.Parallel()
79+
7580
type testData struct {
7681
fileName string
7782
useTransactions bool

0 commit comments

Comments
 (0)