diff --git a/server.go b/server.go index f8f9d03dff4..5cb75a0335e 100644 --- a/server.go +++ b/server.go @@ -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 @@ -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 diff --git a/server_test.go b/server_test.go index 69849156eb0..e834faed7c4 100644 --- a/server_test.go +++ b/server_test.go @@ -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) @@ -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)