From a8a2da31949cb2614715524b7e5c4e0060761cd3 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 4 Mar 2015 12:54:44 -0800 Subject: [PATCH] Transplan 'SHOW TAG VALUES' tests --- cmd/influxd/server_integration_test.go | 40 +++++ httpd/handler_test.go | 202 ------------------------- 2 files changed, 40 insertions(+), 202 deletions(-) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index f90e80527a..b6a810716a 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -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", diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 894f8c0bb3..94a57096d1 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -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")