Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit c6ab546

Browse files
peiqinzhaoRamon Nogueira
authored andcommitted
Add the unit test on expectation of distribution (#10)
1 parent b98abe4 commit c6ab546

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

stats_test.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"go.opencensus.io/stats/view"
2727
"go.opencensus.io/tag"
2828
"google.golang.org/api/option"
29+
"google.golang.org/genproto/googleapis/api/distribution"
2930
"google.golang.org/genproto/googleapis/api/label"
3031
"google.golang.org/genproto/googleapis/api/metric"
3132
metricpb "google.golang.org/genproto/googleapis/api/metric"
@@ -315,7 +316,47 @@ func TestExporter_makeReq(t *testing.T) {
315316
name: "dist agg + time window",
316317
projID: "proj-id",
317318
vd: newTestDistViewData(distView, start, end),
318-
want: nil, //TODO: add expectation for distribution
319+
want: []*monitoringpb.CreateTimeSeriesRequest{{
320+
Name: monitoring.MetricProjectPath("proj-id"),
321+
TimeSeries: []*monitoringpb.TimeSeries{
322+
{
323+
Metric: &metricpb.Metric{
324+
Type: "custom.googleapis.com/opencensus/distview",
325+
Labels: map[string]string{
326+
opencensusTaskKey: taskValue,
327+
},
328+
},
329+
Resource: &monitoredrespb.MonitoredResource{
330+
Type: "global",
331+
},
332+
Points: []*monitoringpb.Point{
333+
{
334+
Interval: &monitoringpb.TimeInterval{
335+
StartTime: &timestamp.Timestamp{
336+
Seconds: start.Unix(),
337+
Nanos: int32(start.Nanosecond()),
338+
},
339+
EndTime: &timestamp.Timestamp{
340+
Seconds: end.Unix(),
341+
Nanos: int32(end.Nanosecond()),
342+
},
343+
},
344+
Value: &monitoringpb.TypedValue{Value: &monitoringpb.TypedValue_DistributionValue{
345+
DistributionValue: &distribution.Distribution{
346+
Count: 5,
347+
Mean: 3.0,
348+
SumOfSquaredDeviation: 1.5,
349+
BucketOptions: &distribution.Distribution_BucketOptions{
350+
Options: &distribution.Distribution_BucketOptions_ExplicitBuckets{
351+
ExplicitBuckets: &distribution.Distribution_BucketOptions_Explicit{
352+
Bounds: []float64{2.0, 4.0, 7.0}}}},
353+
BucketCounts: []int64{2, 2, 1}},
354+
}},
355+
},
356+
},
357+
},
358+
},
359+
}},
319360
},
320361
}
321362
for _, tt := range tests {
@@ -325,9 +366,6 @@ func TestExporter_makeReq(t *testing.T) {
325366
taskValue: taskValue,
326367
}
327368
resps := e.makeReq([]*view.Data{tt.vd}, maxTimeSeriesPerUpload)
328-
if tt.want == nil {
329-
t.Skip("Missing expectation")
330-
}
331369
if got, want := len(resps), len(tt.want); got != want {
332370
t.Fatalf("%v: Exporter.makeReq() returned %d responses; want %d", tt.name, got, want)
333371
}

0 commit comments

Comments
 (0)