mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
adjust mssql tests
This commit is contained in:
parent
af22213462
commit
e303468c0c
@ -143,20 +143,6 @@ func TestMacroEngine(t *testing.T) {
|
|||||||
So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339)))
|
So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339)))
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("interpolate __timeFrom function", func() {
|
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom(time_column)")
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select '%s'", from.Format(time.RFC3339)))
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("interpolate __timeTo function", func() {
|
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__timeTo(time_column)")
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select '%s'", to.Format(time.RFC3339)))
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("interpolate __unixEpochFilter function", func() {
|
Convey("interpolate __unixEpochFilter function", func() {
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time_column)")
|
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time_column)")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@ -177,20 +163,6 @@ func TestMacroEngine(t *testing.T) {
|
|||||||
So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339)))
|
So(sql, ShouldEqual, fmt.Sprintf("WHERE time_column BETWEEN '%s' AND '%s'", from.Format(time.RFC3339), to.Format(time.RFC3339)))
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("interpolate __timeFrom function", func() {
|
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__timeFrom(time_column)")
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select '%s'", from.Format(time.RFC3339)))
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("interpolate __timeTo function", func() {
|
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__timeTo(time_column)")
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select '%s'", to.Format(time.RFC3339)))
|
|
||||||
})
|
|
||||||
|
|
||||||
Convey("interpolate __unixEpochFilter function", func() {
|
Convey("interpolate __unixEpochFilter function", func() {
|
||||||
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time_column)")
|
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time_column)")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -675,6 +675,30 @@ func TestMSSQL(t *testing.T) {
|
|||||||
So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
|
So(queryResult.Series[3].Name, ShouldEqual, "Metric B valueTwo")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("When doing a query with timeFrom,timeTo,unixEpochFrom,unixEpochTo macros", func() {
|
||||||
|
tsdb.Interpolate = origInterpolate
|
||||||
|
query := &tsdb.TsdbQuery{
|
||||||
|
TimeRange: tsdb.NewFakeTimeRange("5m", "now", fromStart),
|
||||||
|
Queries: []*tsdb.Query{
|
||||||
|
{
|
||||||
|
DataSource: &models.DataSource{JsonData: simplejson.New()},
|
||||||
|
Model: simplejson.NewFromAny(map[string]interface{}{
|
||||||
|
"rawSql": `SELECT time FROM metric_values WHERE time > $__timeFrom() OR time < $__timeFrom() OR 1 < $__unixEpochFrom() OR $__unixEpochTo() > 1 ORDER BY 1`,
|
||||||
|
"format": "time_series",
|
||||||
|
}),
|
||||||
|
RefId: "A",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := endpoint.Query(nil, nil, query)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
queryResult := resp.Results["A"]
|
||||||
|
So(queryResult.Error, ShouldBeNil)
|
||||||
|
So(queryResult.Meta.Get("sql").MustString(), ShouldEqual, "SELECT time FROM metric_values WHERE time > '2018-03-15T12:55:00Z' OR time < '2018-03-15T12:55:00Z' OR 1 < 1521118500 OR 1521118800 > 1 ORDER BY 1")
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
Convey("Given a stored procedure that takes @from and @to in epoch time", func() {
|
Convey("Given a stored procedure that takes @from and @to in epoch time", func() {
|
||||||
sql := `
|
sql := `
|
||||||
IF object_id('sp_test_epoch') IS NOT NULL
|
IF object_id('sp_test_epoch') IS NOT NULL
|
||||||
|
Loading…
Reference in New Issue
Block a user