Fix tests for the updated group by time logic

pull/2071/head
Nathan Haugo 2017-10-03 16:31:51 -07:00
parent f5ae39cde3
commit e519759729
2 changed files with 8 additions and 7 deletions

View File

@ -298,11 +298,12 @@ func (g *GroupByVar) parseAbsolute(fragment string) (time.Duration, error) {
} }
func (g *GroupByVar) String() string { func (g *GroupByVar) String() string {
duration := g.Duration.Nanoseconds() / (g.ReportingInterval.Nanoseconds() * int64(g.Resolution)) duration := int64(g.Duration/time.Second) / int64(g.Resolution) * 3
if duration == 0 { if duration == 0 {
duration = 1 duration = 1
} }
return "time(" + strconv.Itoa(int(duration)) + "s)" ress := "time(" + strconv.Itoa(int(duration)) + "s)"
return ress
} }
func (g *GroupByVar) Name() string { func (g *GroupByVar) Name() string {

View File

@ -135,7 +135,7 @@ func TestTemplateReplace(t *testing.T) {
ReportingInterval: 10 * time.Second, ReportingInterval: 10 * time.Second,
}, },
}, },
want: `SELECT mean(usage_idle) from "cpu" where time > now() - 4320h group by time(1555s)`, want: `SELECT mean(usage_idle) from "cpu" where time > now() - 4320h group by time(46656s)`,
}, },
{ {
name: "auto group by without duration", name: "auto group by without duration",
@ -148,7 +148,7 @@ func TestTemplateReplace(t *testing.T) {
ReportingInterval: 10 * time.Second, ReportingInterval: 10 * time.Second,
}, },
}, },
want: `SELECT mean(usage_idle) from "cpu" WHERE time > now() - 4320h group by time(1555s)`, want: `SELECT mean(usage_idle) from "cpu" WHERE time > now() - 4320h group by time(46656s)`,
}, },
{ {
name: "auto group by with :dashboardTime:", name: "auto group by with :dashboardTime:",
@ -170,7 +170,7 @@ func TestTemplateReplace(t *testing.T) {
}, },
}, },
}, },
want: `SELECT mean(usage_idle) from "cpu" WHERE time > now() - 4320h group by time(1555s)`, want: `SELECT mean(usage_idle) from "cpu" WHERE time > now() - 4320h group by time(46656s)`,
}, },
{ {
name: "auto group by failing condition", name: "auto group by failing condition",
@ -192,7 +192,7 @@ func TestTemplateReplace(t *testing.T) {
}, },
}, },
}, },
want: `SELECT mean(usage_idle) FROM "cpu" WHERE time > now() - 1h GROUP BY time(3s)`, want: `SELECT mean(usage_idle) FROM "cpu" WHERE time > now() - 1h GROUP BY time(93s)`,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
@ -274,7 +274,7 @@ func TestGroupByVarString(t *testing.T) {
ReportingInterval: 10 * time.Second, ReportingInterval: 10 * time.Second,
Duration: 24 * time.Hour, Duration: 24 * time.Hour,
}, },
want: "time(12s)", want: "time(369s)",
}, },
{ {
name: "String() outputs a minimum of 1s intervals", name: "String() outputs a minimum of 1s intervals",