Additional test coverage for non-existent fields

pull/3585/head
Cory LaNou 2015-08-06 15:01:34 -05:00
parent e4674d4a19
commit 2d26c2c9fe
1 changed files with 50 additions and 0 deletions

View File

@ -695,6 +695,51 @@ func TestServer_Query_IdenticalTagValues(t *testing.T) {
}
}
// Ensure the server can query a non-existent field
func TestServer_Query_NonExistent(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig(), "")
defer s.Close()
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicyInfo("rp0", 1, 1*time.Hour)); err != nil {
t.Fatal(err)
}
now := now()
test := NewTest("db0", "rp0")
test.write = `cpu,host=server01 value=1 ` + strconv.FormatInt(now.UnixNano(), 10)
test.addQueries([]*Query{
&Query{
name: "selecting value should succeed",
command: `SELECT value FROM db0.rp0.cpu`,
exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["%s",1]]}]}]}`, now.Format(time.RFC3339Nano)),
},
&Query{
name: "selecting non-existent should succeed",
command: `SELECT foo FROM db0.rp0.cpu`,
exp: `{"results":[{}]}`,
},
}...)
if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}
for _, query := range test.queries {
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}
// Ensure the server can query with the count aggregate function
func TestServer_Query_Count(t *testing.T) {
t.Parallel()
@ -1067,6 +1112,11 @@ func TestServer_Query_Alias(t *testing.T) {
command: `SELECT mean(value) as mv, max(value) as mv FROM db0.rp0.cpu`,
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","mv","mv"],"values":[["1970-01-01T00:00:00Z",1.5,2]]}]}]}`,
},
&Query{
name: "double aggregate with non-existent field - SELECT mean(value), max(foo) FROM db0.rp0.cpu",
command: `SELECT mean(value), max(foo) FROM db0.rp0.cpu`,
exp: `{"results":[{"series":[{"name":"cpu","columns":["time","mean","max"],"values":[["1970-01-01T00:00:00Z",1.5,null]]}]}]}`,
},
}...)
if err := test.init(s); err != nil {