Transplan 'SHOW TAG VALUES' tests
parent
e84b338018
commit
a8a2da3194
|
@ -444,6 +444,46 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
expected: `{"results":[{"error":"measurement \"bad\" not found"}]}`,
|
||||
},
|
||||
|
||||
{
|
||||
reset: true,
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [
|
||||
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
|
||||
]}`,
|
||||
query: "SHOW TAG VALUES WITH KEY = host",
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"hostTagValues","columns":["host"],"values":[["server01"],["server02"],["server03"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `SHOW TAG VALUES WITH KEY = "host"`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"hostTagValues","columns":["host"],"values":[["server01"],["server02"],["server03"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `SHOW TAG VALUES FROM cpu WITH KEY = host WHERE region = 'uswest'`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"hostTagValues","columns":["host"],"values":[["server01"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `SHOW TAG VALUES WITH KEY = host WHERE region =~ /ca.*/`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"hostTagValues","columns":["host"],"values":[["server03"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `SHOW TAG VALUES WITH KEY = region WHERE host !~ /server0[12]/`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"regionTagValues","columns":["region"],"values":[["caeast"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `SHOW TAG VALUES FROM cpu WITH KEY IN (host, region) WHERE region = 'uswest'`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"hostTagValues","columns":["host"],"values":[["server01"]]},{"name":"regionTagValues","columns":["region"],"values":[["uswest"]]}]}]}`,
|
||||
},
|
||||
|
||||
// User control tests
|
||||
{
|
||||
name: "show users, no actual users",
|
||||
|
|
|
@ -1322,208 +1322,6 @@ func str2iface(strs []string) []interface{} {
|
|||
return a
|
||||
}
|
||||
|
||||
func TestHandler_serveShowTagValues(t *testing.T) {
|
||||
srvr := OpenAuthlessServer(NewMessagingClient())
|
||||
srvr.CreateDatabase("foo")
|
||||
srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar"))
|
||||
srvr.SetDefaultRetentionPolicy("foo", "bar")
|
||||
s := NewHTTPServer(srvr)
|
||||
defer s.Close()
|
||||
|
||||
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [
|
||||
{"name": "cpu", "tags": {"host": "server01"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server01", "region": "uswest"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server01", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "cpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "gpu", "tags": {"host": "server02", "region": "useast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"name": "gpu", "tags": {"host": "server03", "region": "caeast"},"timestamp": "2009-11-10T23:00:00Z","fields": {"value": 100}}
|
||||
]}`)
|
||||
|
||||
if status != http.StatusOK {
|
||||
t.Log(body)
|
||||
t.Fatalf("unexpected status after write: %d", status)
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
q string
|
||||
r *influxdb.Results
|
||||
err string
|
||||
}{
|
||||
// SHOW TAG VALUES
|
||||
{
|
||||
q: `SHOW TAG VALUES WITH KEY = host`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server01"}),
|
||||
str2iface([]string{"server02"}),
|
||||
str2iface([]string{"server03"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES WITH KEY = "..."
|
||||
{
|
||||
q: `SHOW TAG VALUES WITH KEY = "host"`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server01"}),
|
||||
str2iface([]string{"server02"}),
|
||||
str2iface([]string{"server03"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES FROM ...
|
||||
{
|
||||
q: `SHOW TAG VALUES FROM cpu WITH KEY = host`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server01"}),
|
||||
str2iface([]string{"server02"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES FROM ... WHERE ...
|
||||
{
|
||||
q: `SHOW TAG VALUES FROM cpu WITH KEY = host WHERE region = 'uswest'`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server01"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES FROM ... WHERE =~ regex
|
||||
{
|
||||
q: `SHOW TAG VALUES WITH KEY = host WHERE region =~ /ca.*/`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server03"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES FROM ... WHERE !~ regex
|
||||
{
|
||||
q: `SHOW TAG VALUES WITH KEY = region WHERE host !~ /server0[12]/`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "regionTagValues",
|
||||
Columns: []string{"region"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"caeast"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// SHOW TAG VALUES FROM ... WITH KEY IN ... WHERE ...
|
||||
{
|
||||
q: `SHOW TAG VALUES FROM cpu WITH KEY IN (host, region) WHERE region = 'uswest'`,
|
||||
r: &influxdb.Results{
|
||||
Results: []*influxdb.Result{
|
||||
{
|
||||
Series: []*influxql.Row{
|
||||
{
|
||||
Name: "hostTagValues",
|
||||
Columns: []string{"host"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"server01"}),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "regionTagValues",
|
||||
Columns: []string{"region"},
|
||||
Values: [][]interface{}{
|
||||
str2iface([]string{"uswest"}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
query := map[string]string{"db": "foo", "q": tt.q}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query #%d: %s", i, tt.q)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
|
||||
r := &influxdb.Results{}
|
||||
if err := json.Unmarshal([]byte(body), r); err != nil {
|
||||
t.Logf("query #%d: %s", i, tt.q)
|
||||
t.Log(body)
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tt.err, errstring(r.Err)) {
|
||||
t.Logf("query #%d: %s", i, tt.q)
|
||||
t.Errorf("%d. %s: error mismatch:\n exp=%s\n got=%s\n\n", i, tt.q, tt.err, r.Err)
|
||||
} else if tt.err == "" && !reflect.DeepEqual(tt.r, r) {
|
||||
t.Logf("query #%d: %s", i, tt.q)
|
||||
t.Logf("exp = %s", mustMarshalJSON(tt.r))
|
||||
t.Logf("got = %s", body)
|
||||
t.Errorf("%d. %s: result mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.q, tt.r, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_serveShowFieldKeys(t *testing.T) {
|
||||
srvr := OpenAuthlessServer(NewMessagingClient())
|
||||
srvr.CreateDatabase("foo")
|
||||
|
|
Loading…
Reference in New Issue