@@ -19,6 +19,7 @@ import (
19
19
"go.opentelemetry.io/collector/config/configretry"
20
20
"go.opentelemetry.io/collector/config/configtls"
21
21
"go.opentelemetry.io/collector/exporter/exporterhelper"
22
+ "go.opentelemetry.io/collector/exporter/exporterprofiles"
22
23
"go.opentelemetry.io/collector/exporter/exportertest"
23
24
"go.opentelemetry.io/collector/internal/testutil"
24
25
)
@@ -197,3 +198,143 @@ func TestCreateLogs(t *testing.T) {
197
198
require .NoError (t , err )
198
199
require .NotNil (t , oexp )
199
200
}
201
+
202
+ func TestCreateProfiles (t * testing.T ) {
203
+ endpoint := testutil .GetAvailableLocalAddress (t )
204
+ tests := []struct {
205
+ name string
206
+ config * Config
207
+ mustFailOnStart bool
208
+ }{
209
+ {
210
+ name : "UseSecure" ,
211
+ config : & Config {
212
+ ClientConfig : configgrpc.ClientConfig {
213
+ Endpoint : endpoint ,
214
+ TLSSetting : configtls.ClientConfig {
215
+ Insecure : false ,
216
+ },
217
+ },
218
+ },
219
+ },
220
+ {
221
+ name : "Keepalive" ,
222
+ config : & Config {
223
+ ClientConfig : configgrpc.ClientConfig {
224
+ Endpoint : endpoint ,
225
+ Keepalive : & configgrpc.KeepaliveClientConfig {
226
+ Time : 30 * time .Second ,
227
+ Timeout : 25 * time .Second ,
228
+ PermitWithoutStream : true ,
229
+ },
230
+ },
231
+ },
232
+ },
233
+ {
234
+ name : "NoneCompression" ,
235
+ config : & Config {
236
+ ClientConfig : configgrpc.ClientConfig {
237
+ Endpoint : endpoint ,
238
+ Compression : "none" ,
239
+ },
240
+ },
241
+ },
242
+ {
243
+ name : "GzipCompression" ,
244
+ config : & Config {
245
+ ClientConfig : configgrpc.ClientConfig {
246
+ Endpoint : endpoint ,
247
+ Compression : configcompression .TypeGzip ,
248
+ },
249
+ },
250
+ },
251
+ {
252
+ name : "SnappyCompression" ,
253
+ config : & Config {
254
+ ClientConfig : configgrpc.ClientConfig {
255
+ Endpoint : endpoint ,
256
+ Compression : configcompression .TypeSnappy ,
257
+ },
258
+ },
259
+ },
260
+ {
261
+ name : "ZstdCompression" ,
262
+ config : & Config {
263
+ ClientConfig : configgrpc.ClientConfig {
264
+ Endpoint : endpoint ,
265
+ Compression : configcompression .TypeZstd ,
266
+ },
267
+ },
268
+ },
269
+ {
270
+ name : "Headers" ,
271
+ config : & Config {
272
+ ClientConfig : configgrpc.ClientConfig {
273
+ Endpoint : endpoint ,
274
+ Headers : map [string ]configopaque.String {
275
+ "hdr1" : "val1" ,
276
+ "hdr2" : "val2" ,
277
+ },
278
+ },
279
+ },
280
+ },
281
+ {
282
+ name : "NumConsumers" ,
283
+ config : & Config {
284
+ ClientConfig : configgrpc.ClientConfig {
285
+ Endpoint : endpoint ,
286
+ },
287
+ },
288
+ },
289
+ {
290
+ name : "CaCert" ,
291
+ config : & Config {
292
+ ClientConfig : configgrpc.ClientConfig {
293
+ Endpoint : endpoint ,
294
+ TLSSetting : configtls.ClientConfig {
295
+ Config : configtls.Config {
296
+ CAFile : filepath .Join ("testdata" , "test_cert.pem" ),
297
+ },
298
+ },
299
+ },
300
+ },
301
+ },
302
+ {
303
+ name : "CertPemFileError" ,
304
+ config : & Config {
305
+ ClientConfig : configgrpc.ClientConfig {
306
+ Endpoint : endpoint ,
307
+ TLSSetting : configtls.ClientConfig {
308
+ Config : configtls.Config {
309
+ CAFile : "nosuchfile" ,
310
+ },
311
+ },
312
+ },
313
+ },
314
+ mustFailOnStart : true ,
315
+ },
316
+ }
317
+
318
+ for _ , tt := range tests {
319
+ t .Run (tt .name , func (t * testing.T ) {
320
+ factory := NewFactory ()
321
+ set := exportertest .NewNopSettings ()
322
+ consumer , err := factory .(exporterprofiles.Factory ).CreateProfiles (context .Background (), set , tt .config )
323
+ require .NoError (t , err )
324
+ assert .NotNil (t , consumer )
325
+ err = consumer .Start (context .Background (), componenttest .NewNopHost ())
326
+ if tt .mustFailOnStart {
327
+ require .Error (t , err )
328
+ } else {
329
+ require .NoError (t , err )
330
+ }
331
+ // Shutdown is called even when Start fails
332
+ err = consumer .Shutdown (context .Background ())
333
+ if err != nil {
334
+ // Since the endpoint of OTLP exporter doesn't actually exist,
335
+ // exporter may already stop because it cannot connect.
336
+ assert .Equal (t , "rpc error: code = Canceled desc = grpc: the client connection is closing" , err .Error ())
337
+ }
338
+ })
339
+ }
340
+ }
0 commit comments