@@ -16,19 +16,19 @@ package stackdriver
1616
1717import (
1818 "context"
19- "reflect"
2019 "strings"
2120 "testing"
2221
2322 "github.com/golang/protobuf/ptypes/timestamp"
23+
2424 distributionpb "google.golang.org/genproto/googleapis/api/distribution"
25+ labelpb "google.golang.org/genproto/googleapis/api/label"
2526 googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
2627 monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
2728 monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
2829
2930 "go.opencensus.io/metric/metricdata"
3031 "go.opencensus.io/resource"
31- "time"
3232)
3333
3434var se = & statsExporter {
@@ -74,11 +74,8 @@ func TestMetricResourceToMonitoringResource(t *testing.T) {
7474
7575 for i , tt := range tests {
7676 got := metricRscToMpbRsc (tt .in )
77- if ! reflect .DeepEqual (got , tt .want ) {
78- gj , wj := serializeAsJSON (got ), serializeAsJSON (tt .want )
79- if gj != wj {
80- t .Errorf ("#%d: Unmatched JSON\n Got:\n \t %s\n Want:\n \t %s" , i , gj , wj )
81- }
77+ if diff := cmpResource (got , tt .want ); diff != "" {
78+ t .Fatalf ("Test %d failed. Unexpected Resource -got +want: %s" , i , diff )
8279 }
8380 }
8481}
@@ -136,7 +133,8 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
136133 TimeSeries : []* monitoringpb.TimeSeries {
137134 {
138135 Metric : & googlemetricpb.Metric {
139- Type : "custom.googleapis.com/opencensus/with_metric_descriptor" ,
136+ Type : "custom.googleapis.com/opencensus/with_metric_descriptor" ,
137+ Labels : map [string ]string {},
140138 },
141139 Resource : & monitoredrespb.MonitoredResource {
142140 Type : "global" ,
@@ -207,7 +205,8 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
207205 TimeSeries : []* monitoringpb.TimeSeries {
208206 {
209207 Metric : & googlemetricpb.Metric {
210- Type : "custom.googleapis.com/opencensus/with_metric_descriptor" ,
208+ Type : "custom.googleapis.com/opencensus/with_metric_descriptor" ,
209+ Labels : map [string ]string {},
211210 },
212211 Resource : & monitoredrespb.MonitoredResource {
213212 Type : "global" ,
@@ -258,13 +257,10 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
258257 }
259258
260259 got := se .combineTimeSeriesToCreateTimeSeriesRequest (tsl )
261- if ! reflect .DeepEqual (got , tt .want ) {
262- // Our saving grace is serialization equality since some
263- // unexported fields could be present in the various values.
264- gj , wj := serializeAsJSON (got ), serializeAsJSON (tt .want )
265- if gj != wj {
266- t .Errorf ("#%d: Unmatched JSON\n Got:\n \t %s\n Want:\n \t %s" , i , gj , wj )
267- }
260+ // Our saving grace is serialization equality since some
261+ // unexported fields could be present in the various values.
262+ if diff := cmpTSReqs (got , tt .want ); diff != "" {
263+ t .Fatalf ("Test %d failed. Unexpected CreateTimeSeriesRequests -got +want: %s" , i , diff )
268264 }
269265 }
270266}
@@ -281,6 +277,7 @@ func TestMetricDescriptorToMonitoringMetricDescriptor(t *testing.T) {
281277 want : & googlemetricpb.MetricDescriptor {
282278 Name : "projects/foo/metricDescriptors/custom.googleapis.com/opencensus" ,
283279 Type : "custom.googleapis.com/opencensus" ,
280+ Labels : []* labelpb.LabelDescriptor {},
284281 DisplayName : "OpenCensus" ,
285282 MetricKind : googlemetricpb .MetricDescriptor_GAUGE ,
286283 ValueType : googlemetricpb .MetricDescriptor_INT64 ,
@@ -298,6 +295,7 @@ func TestMetricDescriptorToMonitoringMetricDescriptor(t *testing.T) {
298295 want : & googlemetricpb.MetricDescriptor {
299296 Name : "projects/foo/metricDescriptors/custom.googleapis.com/opencensus/with_metric_descriptor" ,
300297 Type : "custom.googleapis.com/opencensus/with_metric_descriptor" ,
298+ Labels : []* labelpb.LabelDescriptor {},
301299 DisplayName : "OpenCensus/with_metric_descriptor" ,
302300 Description : "This is with metric descriptor" ,
303301 Unit : "By" ,
@@ -321,13 +319,10 @@ func TestMetricDescriptorToMonitoringMetricDescriptor(t *testing.T) {
321319 continue
322320 }
323321
324- if ! reflect .DeepEqual (got , tt .want ) {
325- // Our saving grace is serialization equality since some
326- // unexported fields could be present in the various values.
327- gj , wj := serializeAsJSON (got ), serializeAsJSON (tt .want )
328- if gj != wj {
329- t .Errorf ("#%d: Unmatched JSON\n Got:\n \t %s\n Want:\n \t %s" , i , gj , wj )
330- }
322+ // Our saving grace is serialization equality since some
323+ // unexported fields could be present in the various values.
324+ if diff := cmpMD (got , tt .want ); diff != "" {
325+ t .Fatalf ("Test %d failed. Unexpected MetricDescriptor -got +want: %s" , i , diff )
331326 }
332327 }
333328}
@@ -505,21 +500,10 @@ func TestMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
505500 continue
506501 }
507502
508- if g , w := mpt , tt .want ; ! reflect .DeepEqual (g , w ) {
509- // Our saving grace is serialization equality since some
510- // unexported fields could be present in the various values.
511- gj , wj := serializeAsJSON (g ), serializeAsJSON (w )
512- if gj != wj {
513- t .Errorf ("#%d: Unmatched JSON\n Got:\n \t %s\n Want:\n \t %s" , i , gj , wj )
514- }
503+ // Our saving grace is serialization equality since some
504+ // unexported fields could be present in the various values.
505+ if diff := cmpPoint (mpt , tt .want ); diff != "" {
506+ t .Fatalf ("Test %d failed. Unexpected Point -got +want: %s" , i , diff )
515507 }
516508 }
517509}
518-
519- func timestampToTime (ts * timestamp.Timestamp ) time.Time {
520- if ts == nil {
521- return time .Unix (0 , 0 ).UTC ()
522- } else {
523- return time .Unix (ts .Seconds , int64 (ts .Nanos )).UTC ()
524- }
525- }
0 commit comments