Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not allow empty database name, closes #1950 #1955

Merged
merged 2 commits into from
Mar 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comment is not quite right.

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