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

Parser refactor #2121

Merged
merged 1 commit into from
Apr 9, 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
196 changes: 133 additions & 63 deletions cmd/influxd/server_integration_test.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,6 @@ func (m *Measurement) tagValuesByKeyAndSeriesID(tagKeys []string, ids seriesIDs)
// Iterate the tag keys we're interested in and collect values
// from this series, if they exist.
for _, tagKey := range tagKeys {
tagKey = strings.Trim(tagKey, `"`)
if tagVal, ok := s.Tags[tagKey]; ok {
if _, ok = tagValues[tagKey]; !ok {
tagValues[tagKey] = newStringSet()
Expand Down
16 changes: 11 additions & 5 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/httptest"
"net/url"
"os"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -151,13 +152,13 @@ func TestHandler_ShowMeasurementsNotFound(t *testing.T) {
status, body := MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SHOW SERIES from bin", "db": "foo"}, nil, "")
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"measurement \"bin\" not found"}]}` {
} else if !matchRegex(`measurement not found: .*bin`, body) {
t.Fatalf("unexpected body: %s", body)
}
status, body = MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "SELECT * FROM bin", "db": "foo"}, nil, "")
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"measurement not found: \"foo\".\"bar\".\"bin\""}]}` {
} else if !matchRegex(`measurement not found: .*bin`, body) {
t.Fatalf("unexpected body: %s", body)
}
}
Expand Down Expand Up @@ -256,7 +257,7 @@ func TestHandler_DropDatabase_NotFound(t *testing.T) {
status, body := MustHTTP("GET", s.URL+`/query`, map[string]string{"q": "DROP DATABASE bar"}, nil, "")
if status != http.StatusInternalServerError {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"database not found"}]}` {
} else if !matchRegex(`database not found: bar.*`, body) {
t.Fatalf("unexpected body: %s", body)
}
}
Expand Down Expand Up @@ -290,7 +291,7 @@ func TestHandler_RetentionPolicies_DatabaseNotFound(t *testing.T) {

if status != http.StatusInternalServerError {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"database not found"}]}` {
} else if !matchRegex(`database not found: foo.*`, body) {
t.Fatalf("unexpected body: %s", body)
}
}
Expand Down Expand Up @@ -502,7 +503,7 @@ func TestHandler_DeleteRetentionPolicy_DatabaseNotFound(t *testing.T) {

if status != http.StatusInternalServerError {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{"error":"database not found"}]}` {
} else if !matchRegex(`database not found: .*qux.*`, body) {
t.Fatalf("unexpected body: %s", body)
}
}
Expand Down Expand Up @@ -1859,3 +1860,8 @@ func mustMarshalJSON(i interface{}) string {
}
return string(b)
}

// matchRegex tests that the string matches the pattern
func matchRegex(pattern, s string) bool {
return regexp.MustCompile(pattern).MatchString(s)
}
21 changes: 15 additions & 6 deletions influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"runtime"
"time"

"github.com/influxdb/influxdb/client"
Expand Down Expand Up @@ -48,9 +49,6 @@ var (
// ErrDatabaseExists is returned when creating a duplicate database.
ErrDatabaseExists = errors.New("database exists")

// ErrDatabaseNotFound is returned when dropping a non-existent database.
ErrDatabaseNotFound = errors.New("database not found")

// ErrDatabaseRequired is returned when using a blank database name.
ErrDatabaseRequired = errors.New("database required")

Expand Down Expand Up @@ -107,9 +105,6 @@ var (
// ErrMeasurementNameRequired is returned when a point does not contain a name.
ErrMeasurementNameRequired = errors.New("measurement name required")

// ErrMeasurementNotFound is returned when a measurement does not exist.
ErrMeasurementNotFound = errors.New("measurement not found")

// ErrFieldsRequired is returned when a point does not any fields.
ErrFieldsRequired = errors.New("fields required")

Expand Down Expand Up @@ -147,6 +142,20 @@ var (
ErrContinuousQueryNotFound = errors.New("continuous query not found")
)

func ErrDatabaseNotFound(name string) error { return Errorf("database not found: %s", name) }

func ErrMeasurementNotFound(name string) error { return Errorf("measurement not found: %s", name) }

func Errorf(format string, a ...interface{}) (err error) {
if _, file, line, ok := runtime.Caller(2); ok {
a = append(a, file, line)
err = fmt.Errorf(format+" (%s:%d)", a...)
} else {
err = fmt.Errorf(format, a...)
}
return
}

// ErrAuthorize represents an authorization error.
type ErrAuthorize struct {
text string
Expand Down
Loading