@@ -23,11 +23,61 @@ import (
2323 "github.com/golang/protobuf/ptypes/timestamp"
2424 distributionpb "google.golang.org/genproto/googleapis/api/distribution"
2525 googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
26+ monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
2627 monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
2728
2829 metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
30+ resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
2931)
3032
33+ func TestProtoResourceToMonitoringResource (t * testing.T ) {
34+ tests := []struct {
35+ in * resourcepb.Resource
36+ want * monitoredrespb.MonitoredResource
37+ }{
38+ {in : nil , want : nil },
39+ {in : & resourcepb.Resource {}, want : & monitoredrespb.MonitoredResource {}},
40+ {
41+ in : & resourcepb.Resource {
42+ Type : "foo" ,
43+ },
44+ want : & monitoredrespb.MonitoredResource {
45+ Type : "foo" ,
46+ },
47+ },
48+ {
49+ in : & resourcepb.Resource {
50+ Type : "foo" ,
51+ Labels : map [string ]string {},
52+ },
53+ want : & monitoredrespb.MonitoredResource {
54+ Type : "foo" ,
55+ Labels : map [string ]string {},
56+ },
57+ },
58+ {
59+ in : & resourcepb.Resource {
60+ Type : "foo" ,
61+ Labels : map [string ]string {"a" : "A" },
62+ },
63+ want : & monitoredrespb.MonitoredResource {
64+ Type : "foo" ,
65+ Labels : map [string ]string {"a" : "A" },
66+ },
67+ },
68+ }
69+
70+ for i , tt := range tests {
71+ got := protoResourceToMonitoredResource (tt .in )
72+ if ! reflect .DeepEqual (got , tt .want ) {
73+ gj , wj := serializeAsJSON (got ), serializeAsJSON (tt .want )
74+ if gj != wj {
75+ t .Errorf ("#%d: Unmatched JSON\n Got:\n \t %s\n Want:\n \t %s" , i , gj , wj )
76+ }
77+ }
78+ }
79+ }
80+
3181func TestProtoToMonitoringMetricDescriptor (t * testing.T ) {
3282 tests := []struct {
3383 in * metricspb.Metric
0 commit comments