|
|
|
|
@ -10,6 +10,10 @@ import ( |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp" |
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data" |
|
|
|
|
"github.com/xorcare/pointer" |
|
|
|
|
|
|
|
|
|
influxdb2 "github.com/influxdata/influxdb-client-go" |
|
|
|
|
"github.com/influxdata/influxdb-client-go/api" |
|
|
|
|
) |
|
|
|
|
@ -152,6 +156,59 @@ func TestExecuteGrouping(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAggregateGrouping(t *testing.T) { |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
t.Run("Grouping Test", func(t *testing.T) { |
|
|
|
|
runner := &MockRunner{ |
|
|
|
|
testDataPath: "aggregate.csv", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dr := ExecuteQuery(ctx, QueryModel{MaxDataPoints: 100}, runner, 50) |
|
|
|
|
if dr.Error != nil { |
|
|
|
|
t.Fatal(dr.Error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(dr.Frames) != 1 { |
|
|
|
|
t.Fatal("Expected one frame") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
str, _ := dr.Frames[0].StringTable(-1, -1) |
|
|
|
|
fmt.Println(str) |
|
|
|
|
|
|
|
|
|
// `Name:
|
|
|
|
|
// Dimensions: 2 Fields by 3 Rows
|
|
|
|
|
// +-------------------------------+--------------------------+
|
|
|
|
|
// | Name: Time | Name: |
|
|
|
|
|
// | Labels: | Labels: host=hostname.ru |
|
|
|
|
|
// | Type: []time.Time | Type: []*float64 |
|
|
|
|
|
// +-------------------------------+--------------------------+
|
|
|
|
|
// | 2020-06-05 12:06:00 +0000 UTC | 8.291 |
|
|
|
|
|
// | 2020-06-05 12:07:00 +0000 UTC | 0.534 |
|
|
|
|
|
// | 2020-06-05 12:08:00 +0000 UTC | 0.667 |
|
|
|
|
|
// +-------------------------------+--------------------------+
|
|
|
|
|
// `
|
|
|
|
|
|
|
|
|
|
expectedFrame := data.NewFrame("", |
|
|
|
|
data.NewField("Time", nil, []time.Time{ |
|
|
|
|
time.Date(2020, 6, 5, 12, 6, 0, 0, time.UTC), |
|
|
|
|
time.Date(2020, 6, 5, 12, 7, 0, 0, time.UTC), |
|
|
|
|
time.Date(2020, 6, 5, 12, 8, 0, 0, time.UTC), |
|
|
|
|
}), |
|
|
|
|
data.NewField("", map[string]string{"host": "hostname.ru"}, []*float64{ |
|
|
|
|
pointer.Float64(8.291), |
|
|
|
|
pointer.Float64(0.534), |
|
|
|
|
pointer.Float64(0.667), |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|
expectedFrame.Meta = &data.FrameMeta{} |
|
|
|
|
|
|
|
|
|
if diff := cmp.Diff(expectedFrame, dr.Frames[0], data.FrameTestCompareOptions()...); diff != "" { |
|
|
|
|
t.Errorf("Result mismatch (-want +got):\n%s", diff) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBuckets(t *testing.T) { |
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
|