@@ -50,14 +50,52 @@ func TestLogWriter(t *testing.T) {
50
50
assert .Len (t , messages , 2 )
51
51
}
52
52
53
- func TestExportTraceData (t * testing.T ) {
53
+ func testTraceData (t * testing.T , expected [] Span , td consumerdata. TraceData ) {
54
54
ctx , cancel := context .WithCancel (context .Background ())
55
55
defer cancel ()
56
56
57
- m := & Mock {make ([]Data , 0 , 3 )}
57
+ m := & Mock {make ([]Data , 0 , 1 )}
58
58
srv := m .Server ()
59
59
defer srv .Close ()
60
60
61
+ f := NewFactory ()
62
+ c := f .CreateDefaultConfig ().(* Config )
63
+ c .APIKey , c .SpansURLOverride = "1" , srv .URL
64
+ params := component.ExporterCreateParams {Logger : zap .NewNop ()}
65
+ exp , err := f .CreateTraceExporter (context .Background (), params , c )
66
+ require .NoError (t , err )
67
+ require .NoError (t , exp .ConsumeTraces (ctx , internaldata .OCToTraceData (td )))
68
+ require .NoError (t , exp .Shutdown (ctx ))
69
+ assert .Equal (t , expected , m .Spans ())
70
+ }
71
+
72
+ func TestExportTraceDataMinimum (t * testing.T ) {
73
+ td := consumerdata.TraceData {
74
+ Spans : []* tracepb.Span {
75
+ {
76
+ TraceId : []byte {1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 },
77
+ SpanId : []byte {0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 },
78
+ Name : & tracepb.TruncatableString {Value : "root" },
79
+ },
80
+ },
81
+ }
82
+
83
+ expected := []Span {
84
+ {
85
+ ID : "0000000000000001" ,
86
+ TraceID : "01010101010101010101010101010101" ,
87
+ Attributes : map [string ]interface {}{
88
+ "collector.name" : name ,
89
+ "collector.version" : version ,
90
+ "name" : "root" ,
91
+ },
92
+ },
93
+ }
94
+
95
+ testTraceData (t , expected , td )
96
+ }
97
+
98
+ func TestExportTraceDataFullTrace (t * testing.T ) {
61
99
td := consumerdata.TraceData {
62
100
Node : & commonpb.Node {
63
101
ServiceInfo : & commonpb.ServiceInfo {Name : "test-service" },
@@ -91,15 +129,6 @@ func TestExportTraceData(t *testing.T) {
91
129
},
92
130
}
93
131
94
- f := NewFactory ()
95
- c := f .CreateDefaultConfig ().(* Config )
96
- c .APIKey , c .SpansURLOverride = "1" , srv .URL
97
- params := component.ExporterCreateParams {Logger : zap .NewNop ()}
98
- exp , err := f .CreateTraceExporter (context .Background (), params , c )
99
- require .NoError (t , err )
100
- require .NoError (t , exp .ConsumeTraces (ctx , internaldata .OCToTraceData (td )))
101
- require .NoError (t , exp .Shutdown (ctx ))
102
-
103
132
expected := []Span {
104
133
{
105
134
ID : "0000000000000001" ,
@@ -138,17 +167,87 @@ func TestExportTraceData(t *testing.T) {
138
167
},
139
168
}
140
169
141
- assert . Equal (t , expected , m . Spans () )
170
+ testTraceData (t , expected , td )
142
171
}
143
172
144
- func TestExportMetricData (t * testing.T ) {
173
+ func testExportMetricData (t * testing.T , expected [] Metric , md consumerdata. MetricsData ) {
145
174
ctx , cancel := context .WithCancel (context .Background ())
146
175
defer cancel ()
147
176
148
177
m := & Mock {make ([]Data , 0 , 3 )}
149
178
srv := m .Server ()
150
179
defer srv .Close ()
151
180
181
+ f := NewFactory ()
182
+ c := f .CreateDefaultConfig ().(* Config )
183
+ c .APIKey , c .MetricsURLOverride = "1" , srv .URL
184
+ params := component.ExporterCreateParams {Logger : zap .NewNop ()}
185
+ exp , err := f .CreateMetricsExporter (context .Background (), params , c )
186
+ require .NoError (t , err )
187
+ require .NoError (t , exp .ConsumeMetrics (ctx , internaldata .OCToMetrics (md )))
188
+ require .NoError (t , exp .Shutdown (ctx ))
189
+ assert .Equal (t , expected , m .Metrics ())
190
+ }
191
+
192
+ func TestExportMetricDataMinimal (t * testing.T ) {
193
+ desc := "physical property of matter that quantitatively expresses hot and cold"
194
+ unit := "K"
195
+ md := consumerdata.MetricsData {
196
+ Metrics : []* metricspb.Metric {
197
+ {
198
+ MetricDescriptor : & metricspb.MetricDescriptor {
199
+ Name : "temperature" ,
200
+ Description : desc ,
201
+ Unit : unit ,
202
+ Type : metricspb .MetricDescriptor_GAUGE_DOUBLE ,
203
+ LabelKeys : []* metricspb.LabelKey {
204
+ {Key : "location" },
205
+ {Key : "elevation" },
206
+ },
207
+ },
208
+ Timeseries : []* metricspb.TimeSeries {
209
+ {
210
+ LabelValues : []* metricspb.LabelValue {
211
+ {Value : "Portland" , HasValue : true },
212
+ {Value : "0" , HasValue : true },
213
+ },
214
+ Points : []* metricspb.Point {
215
+ {
216
+ Timestamp : & timestamppb.Timestamp {
217
+ Seconds : 100 ,
218
+ },
219
+ Value : & metricspb.Point_DoubleValue {
220
+ DoubleValue : 293.15 ,
221
+ },
222
+ },
223
+ },
224
+ },
225
+ },
226
+ },
227
+ },
228
+ }
229
+
230
+ expected := []Metric {
231
+ {
232
+ Name : "temperature" ,
233
+ Type : "gauge" ,
234
+ Value : 293.15 ,
235
+ Timestamp : int64 (100 * time .Microsecond ),
236
+ Attributes : map [string ]interface {}{
237
+ "collector.name" : name ,
238
+ "collector.version" : version ,
239
+ "description" : desc ,
240
+ "unit" : unit ,
241
+ "location" : "Portland" ,
242
+ "elevation" : "0" ,
243
+ },
244
+ },
245
+ }
246
+
247
+ testExportMetricData (t , expected , md )
248
+ }
249
+
250
+ func TestExportMetricDataFull (t * testing.T ) {
152
251
desc := "physical property of matter that quantitatively expresses hot and cold"
153
252
unit := "K"
154
253
md := consumerdata.MetricsData {
@@ -234,15 +333,6 @@ func TestExportMetricData(t *testing.T) {
234
333
},
235
334
}
236
335
237
- f := NewFactory ()
238
- c := f .CreateDefaultConfig ().(* Config )
239
- c .APIKey , c .MetricsURLOverride = "1" , srv .URL
240
- params := component.ExporterCreateParams {Logger : zap .NewNop ()}
241
- exp , err := f .CreateMetricsExporter (context .Background (), params , c )
242
- require .NoError (t , err )
243
- require .NoError (t , exp .ConsumeMetrics (ctx , internaldata .OCToMetrics (md )))
244
- require .NoError (t , exp .Shutdown (ctx ))
245
-
246
336
expected := []Metric {
247
337
{
248
338
Name : "temperature" ,
@@ -326,5 +416,5 @@ func TestExportMetricData(t *testing.T) {
326
416
},
327
417
}
328
418
329
- assert . Equal (t , expected , m . Metrics () )
419
+ testExportMetricData (t , expected , md )
330
420
}
0 commit comments