From d133095bcc8c4477d1bebb87cd5d3f7c2227a94f Mon Sep 17 00:00:00 2001 From: 1vn Date: Tue, 13 Nov 2018 13:17:10 -0500 Subject: [PATCH] update tests to output binaries to bin --- .gitignore | 5 +---- fix_test.go | 18 +++++++++--------- goose_test.go | 39 +++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 39e9753..e558613 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,8 @@ cmd/goose/goose* *.test # Files output by tests -custom-goose +bin go.db -goose sql.db -# don't ignore goose dir -!goose/ diff --git a/fix_test.go b/fix_test.go index 956070c..14672d2 100644 --- a/fix_test.go +++ b/fix_test.go @@ -20,12 +20,12 @@ func TestFix(t *testing.T) { defer os.Remove("goose") // clean up commands := []string{ - "go build -i -o goose ./cmd/goose", - fmt.Sprintf("./goose -dir=%s create create_table", dir), - fmt.Sprintf("./goose -dir=%s create add_users", dir), - fmt.Sprintf("./goose -dir=%s create add_indices", dir), - fmt.Sprintf("./goose -dir=%s create update_users", dir), - fmt.Sprintf("./goose -dir=%s fix", dir), + "go build -i -o ./bin/goose ./cmd/goose", + fmt.Sprintf("./bin/goose -dir=%s create create_table", dir), + fmt.Sprintf("./bin/goose -dir=%s create add_users", dir), + fmt.Sprintf("./bin/goose -dir=%s create add_indices", dir), + fmt.Sprintf("./bin/goose -dir=%s create update_users", dir), + fmt.Sprintf("./bin/goose -dir=%s fix", dir), } for _, cmd := range commands { @@ -52,9 +52,9 @@ func TestFix(t *testing.T) { // add more migrations and then fix it commands = []string{ - fmt.Sprintf("./goose -dir=%s create remove_column", dir), - fmt.Sprintf("./goose -dir=%s create create_books_table", dir), - fmt.Sprintf("./goose -dir=%s fix", dir), + fmt.Sprintf("./bin/goose -dir=%s create remove_column", dir), + fmt.Sprintf("./bin/goose -dir=%s create create_books_table", dir), + fmt.Sprintf("./bin/goose -dir=%s fix", dir), } for _, cmd := range commands { diff --git a/goose_test.go b/goose_test.go index 5b719ed..e3e1b76 100644 --- a/goose_test.go +++ b/goose_test.go @@ -1,6 +1,9 @@ package goose import ( + "fmt" + "io/ioutil" + "os" "os/exec" "strings" "testing" @@ -8,11 +11,11 @@ import ( func TestDefaultBinary(t *testing.T) { commands := []string{ - "go build -i -o goose ./cmd/goose", - "./goose -dir=examples/sql-migrations sqlite3 sql.db up", - "./goose -dir=examples/sql-migrations sqlite3 sql.db version", - "./goose -dir=examples/sql-migrations sqlite3 sql.db down", - "./goose -dir=examples/sql-migrations sqlite3 sql.db status", + "go build -i -o ./bin/goose ./cmd/goose", + "./bin/goose -dir=examples/sql-migrations sqlite3 sql.db up", + "./bin/goose -dir=examples/sql-migrations sqlite3 sql.db version", + "./bin/goose -dir=examples/sql-migrations sqlite3 sql.db down", + "./bin/goose -dir=examples/sql-migrations sqlite3 sql.db status", } for _, cmd := range commands { @@ -25,15 +28,23 @@ func TestDefaultBinary(t *testing.T) { } func TestLiteBinary(t *testing.T) { + dir, err := ioutil.TempDir("", "tmptest") + if err != nil { + t.Fatal(err) + } + + defer os.RemoveAll(dir) // clean up + defer os.Remove("goose") // clean up + commands := []string{ - "./goose -dir=examples/sql-migrations create user_indices sql", - "./goose -dir=examples/sql-migrations fix", + fmt.Sprintf("./bin/goose -dir=%s create user_indices sql", dir), + fmt.Sprintf("./bin/goose -dir=%s fix", dir), } // this has to be done outside of the loop // since go only supports space separated tags list. - cmd := "go build -tags='no_mysql no_sqlite no_psql' -i -o goose ./cmd/goose" - out, err := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-i", "-o", "goose", "./cmd/goose").CombinedOutput() + cmd := "go build -tags='no_mysql no_sqlite no_psql' -i -o ./bin/goose ./cmd/goose" + out, err := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-i", "-o", "./bin/goose", "./cmd/goose").CombinedOutput() if err != nil { t.Fatalf("%s:\n%v\n\n%s", err, cmd, out) } @@ -49,11 +60,11 @@ func TestLiteBinary(t *testing.T) { func TestCustomBinary(t *testing.T) { commands := []string{ - "go build -i -o custom-goose ./examples/go-migrations", - "./custom-goose -dir=examples/go-migrations sqlite3 go.db up", - "./custom-goose -dir=examples/go-migrations sqlite3 go.db version", - "./custom-goose -dir=examples/go-migrations sqlite3 go.db down", - "./custom-goose -dir=examples/go-migrations sqlite3 go.db status", + "go build -i -o ./bin/custom-goose ./examples/go-migrations", + "./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db up", + "./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db version", + "./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db down", + "./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db status", } for _, cmd := range commands {