Skip to content

Commit

Permalink
Fix MySQL tests and add trap cleanup for test.sh (#32)
Browse files Browse the repository at this point in the history
* Fix MySQL tests and add trap cleanup for test.sh

* Fix comment formatting
  • Loading branch information
stanislas-m authored Nov 1, 2018
1 parent 7a5999c commit c5c75a8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ then
verbose="-v"
fi

function cleanup {
echo "Cleanup resources..."
docker-compose down
find ./sql_scripts/sqlite -name *.sqlite* -delete
}
# defer cleanup, so it will be executed even after premature exit
trap cleanup EXIT

docker-compose up -d
sleep 10 # Ensure mysql is online

Expand All @@ -30,7 +38,3 @@ test "postgres"
test "cockroach"
test "mysql"
test "sqlite"

docker-compose down

find ./sql_scripts/sqlite -name *.sqlite* -delete
2 changes: 1 addition & 1 deletion translators/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *MySQL) RenameColumn(t fizz.Table) (string, error) {
}
}
col := p.buildColumn(c)
col = strings.Replace(col, oc.Name, fmt.Sprintf("%s %s", oc.Name, nc.Name), -1)
col = strings.Replace(col, oc.Name, fmt.Sprintf("%s` `%s", oc.Name, nc.Name), -1)
s := fmt.Sprintf("ALTER TABLE %s CHANGE %s;", p.escapeIdentifier(t.Name), col)
return s, nil
}
Expand Down
2 changes: 2 additions & 0 deletions translators/mysql_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (p *mysqlSchema) Version() (*semver.Version, error) {
if err != nil {
return version, errors.WithMessage(err, "could not fetch MySQL version")
}
defer res.Close()

for res.Next() {
err = res.Scan(&version)
Expand All @@ -77,6 +78,7 @@ func (p *mysqlSchema) Build() error {
if err != nil {
return err
}
defer res.Close()
for res.Next() {
table := &fizz.Table{
Columns: []fizz.Column{},
Expand Down
4 changes: 2 additions & 2 deletions translators/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var myt = translators.NewMySQL("", "")

func init() {
u := "%s:%s@(%s:%s)/%s?parseTime=true&multiStatements=true&readTimeout=1s&collation=%s"
u = fmt.Sprintf(u, envy.Get("MYSQL_USER", "root"), envy.Get("MYSQL_PASSWORD", ""), envy.Get("MYSQL_HOST", "127.0.0.1"), envy.Get("MYSQL_PORT", "3306"), "pop_test", "utf8_general_ci")
u = fmt.Sprintf(u, envy.Get("MYSQL_USER", "root"), envy.Get("MYSQL_PASSWORD", "root"), envy.Get("MYSQL_HOST", "127.0.0.1"), envy.Get("MYSQL_PORT", "3306"), "pop_test", "utf8_general_ci")
myt = translators.NewMySQL(u, "pop_test")
}

Expand Down Expand Up @@ -280,7 +280,7 @@ func (p *MySQLSuite) Test_MySQL_RenameIndex() {

ddl := `ALTER TABLE ` + "`users`" + ` RENAME INDEX ` + "`email_idx`" + ` TO ` + "`email_address_idx`" + `;`

res, err := fizz.AString(`rename_index("users", "email_idx", "email_address_ix")`, myt)
res, err := fizz.AString(`rename_index("users", "email_idx", "email_address_idx")`, myt)
r.NoError(err)
r.Equal(ddl, res)
}
Expand Down
2 changes: 1 addition & 1 deletion translators/translators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSpecificSuites(t *testing.T) {
suite.Run(t, &PostgreSQLSuite{})
case "cockroach":
suite.Run(t, &CockroachSuite{})
case "mysql":
case "mysql", "mysql_travis":
suite.Run(t, &MySQLSuite{})
case "sqlite":
suite.Run(t, &SQLiteSuite{})
Expand Down

0 comments on commit c5c75a8

Please sign in to comment.