Skip to content

Commit

Permalink
Allow creating databases with dashes in the name
Browse files Browse the repository at this point in the history
  • Loading branch information
mboulton-fathom committed Nov 6, 2023
1 parent 3320fcf commit 8002748
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion prepare_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func defaultCreateDatabase(port uint32, username, password, database string) (er
err = connectionClose(db, err)
}()

if _, err := db.Exec(fmt.Sprintf("CREATE DATABASE %s", database)); err != nil {
if _, err := db.Exec(fmt.Sprintf("CREATE DATABASE \"%s\"", database)); err != nil {
return errorCustomDatabase(database, err)
}

Expand Down
14 changes: 14 additions & 0 deletions prepare_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ func Test_defaultCreateDatabase_ErrorWhenSQLOpenError(t *testing.T) {
assert.EqualError(t, err, "unable to connect to create database with custom name database with the following error: client_encoding must be absent or 'UTF8'")
}

func Test_defaultCreateDatabase_DashesInName(t *testing.T) {
database := NewDatabase(DefaultConfig().
Port(9832).
Database("my-cool-database"))

if err := database.Start(); err != nil {
t.Fatal(err)
}

if err := database.Stop(); err != nil {
t.Fatal(err)
}
}

func Test_defaultCreateDatabase_ErrorWhenQueryError(t *testing.T) {
database := NewDatabase(DefaultConfig().
Port(9831).
Expand Down

0 comments on commit 8002748

Please sign in to comment.