forked from timescale/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in rrk/cass-query-gen-test (pull request timescale#82)
Refactor query generation for Cassandra; add tests Approved-by: Lee Hampton <leejhampton@gmail.com>
- Loading branch information
Showing
4 changed files
with
151 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
cmd/tsbs_generate_queries/databases/cassandra/devops_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package cassandra | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"bitbucket.org/440-labs/tsbs/query" | ||
) | ||
|
||
func TestDevopsGetHostWhereWithHostnames(t *testing.T) { | ||
cases := []struct { | ||
desc string | ||
hostnames []string | ||
want []string | ||
}{ | ||
{ | ||
desc: "single host", | ||
hostnames: []string{"foo1"}, | ||
want: []string{"hostname=foo1"}, | ||
}, | ||
{ | ||
desc: "multi host", | ||
hostnames: []string{"foo1", "foo2"}, | ||
want: []string{"hostname=foo1", "hostname=foo2"}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
d := NewDevops(time.Now(), time.Now(), 10) | ||
|
||
got := d.getHostWhereWithHostnames(c.hostnames) | ||
if len(got) != len(c.want) { | ||
t.Errorf("%s: incorrect output len: got %d want %d", c.desc, len(got), len(c.want)) | ||
} | ||
for i := range c.want { | ||
if got[i] != c.want[i] { | ||
t.Errorf("%s: incorrect output at %d: got %s want %s", c.desc, i, got[i], c.want[i]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestDevopsFillInQuery(t *testing.T) { | ||
humanLabel := "this is my label" | ||
humanDesc := "and now my description" | ||
aggType := "sum" | ||
fields := []string{"foo1, foo2"} | ||
tags := [][]string{{"foo=val", "bar=val2"}} | ||
now := time.Now() | ||
|
||
d := NewDevops(now, now.Add(time.Nanosecond), 10) | ||
qi := d.GenerateEmptyQuery() | ||
q := qi.(*query.Cassandra) | ||
if len(q.HumanLabel) != 0 { | ||
t.Errorf("empty query has non-zero length human label") | ||
} | ||
if len(q.HumanDescription) != 0 { | ||
t.Errorf("empty query has non-zero length human desc") | ||
} | ||
if len(q.AggregationType) != 0 { | ||
t.Errorf("empty query has non-zero length agg type") | ||
} | ||
if len(q.MeasurementName) != 0 { | ||
t.Errorf("empty query has non-zero length measurement name") | ||
} | ||
if len(q.FieldName) != 0 { | ||
t.Errorf("empty query has non-zero length field name") | ||
} | ||
if len(q.TagSets) != 0 { | ||
t.Errorf("empty query has non-zero length tagset") | ||
} | ||
|
||
d.fillInQuery(q, humanLabel, humanDesc, aggType, fields, d.Interval, tags) | ||
|
||
if got := string(q.HumanLabel); got != humanLabel { | ||
t.Errorf("filled query mislabeled: got %s want %s", got, humanLabel) | ||
} | ||
if got := string(q.HumanDescription); got != humanDesc { | ||
t.Errorf("filled query mis-described: got %s want %s", got, humanDesc) | ||
} | ||
if got := string(q.AggregationType); got != aggType { | ||
t.Errorf("filled query has wrong agg type: got %s want %s", got, aggType) | ||
} | ||
if got := string(q.MeasurementName); got != "cpu" { | ||
t.Errorf("filled query has wrong measurement name: got %s want %s", got, "cpu") | ||
} | ||
if got := string(q.FieldName); got != strings.Join(fields, ",") { | ||
t.Errorf("filled query has wrong fields: got %s want %s", got, strings.Join(fields, ",")) | ||
} | ||
if got := q.TimeStart.UnixNano(); got != now.UnixNano() { | ||
t.Errorf("filled query start time wrong: got %d want %d", got, now.UnixNano()) | ||
} | ||
if got := q.TimeEnd.UnixNano(); got != now.UnixNano()+1 { | ||
t.Errorf("filled query end time wrong: got %d want %d", got, now.UnixNano()+1) | ||
} | ||
if got := len(q.TagSets); got != len(tags) { | ||
t.Errorf("filled query has wrong tagset length: got %d want %d", got, len(tags)) | ||
} | ||
for i := range tags { | ||
if got := len(q.TagSets[i]); got != len(tags[i]) { | ||
t.Errorf("tag set len %d not equal: got %d want %d", i, got, len(tags[i])) | ||
} | ||
for j := range tags[i] { | ||
if got := q.TagSets[i][j]; got != tags[i][j] { | ||
t.Errorf("tag set at %d,%d incorrect: got %s want %s", i, j, got, tags[i][j]) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters