Skip to content

Commit

Permalink
Merge pull request #1955 from dullgiulio/nonempty-db-name
Browse files Browse the repository at this point in the history
do not allow empty database name, closes #1950
  • Loading branch information
otoolep committed Mar 14, 2015
2 parents 36fc4c3 + 2cc2077 commit 9723d3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ func (s *Server) Databases() (a []string) {

// CreateDatabase creates a new database.
func (s *Server) CreateDatabase(name string) error {
if name == "" {
return ErrDatabaseNameRequired
}
c := &createDatabaseCommand{Name: name}
_, err := s.broadcast(createDatabaseMessageType, c)
return err
Expand Down Expand Up @@ -795,6 +798,9 @@ func (s *Server) applyCreateDatabase(m *messaging.Message) (err error) {

// DropDatabase deletes an existing database.
func (s *Server) DropDatabase(name string) error {
if name == "" {
return ErrDatabaseNameRequired
}
c := &dropDatabaseCommand{Name: name}
_, err := s.broadcast(dropDatabaseMessageType, c)
return err
Expand Down
10 changes: 10 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func TestServer_CreateDatabase(t *testing.T) {
s := OpenServer(NewMessagingClient())
defer s.Close()

// Attempt creating empty name database.
if err := s.CreateDatabase(""); err != influxdb.ErrDatabaseNameRequired {
t.Fatal("expected error on empty database name")
}

// Create the "foo" database.
if err := s.CreateDatabase("foo"); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -321,6 +326,11 @@ func TestServer_DropDatabase(t *testing.T) {
s := OpenServer(NewMessagingClient())
defer s.Close()

// Attempt creating empty name database.
if err := s.DropDatabase(""); err != influxdb.ErrDatabaseNameRequired {
t.Fatal("expected error on empty database name")
}

// Create the "foo" database and verify it exists.
if err := s.CreateDatabase("foo"); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 9723d3f

Please sign in to comment.