@@ -29,6 +29,7 @@ import (
29
29
"go.opentelemetry.io/collector/exporter/exporterbatcher"
30
30
"go.opentelemetry.io/collector/exporter/exportertest"
31
31
"go.opentelemetry.io/collector/exporter/xexporter"
32
+ "go.opentelemetry.io/collector/extension"
32
33
"go.opentelemetry.io/collector/extension/extensionauth"
33
34
"go.opentelemetry.io/collector/pdata/pcommon"
34
35
"go.opentelemetry.io/collector/pdata/plog"
@@ -41,13 +42,6 @@ import (
41
42
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/metadata"
42
43
)
43
44
44
- func build [T any , O any ](t * testing.T , f func (... O ) (T , error ), opts ... O ) T {
45
- t .Helper ()
46
- v , err := f (opts ... )
47
- require .NoError (t , err )
48
- return v
49
- }
50
-
51
45
func TestExporterLogs (t * testing.T ) {
52
46
t .Run ("publish with success" , func (t * testing.T ) {
53
47
rec := newBulkRecorder ()
@@ -2173,17 +2167,13 @@ func TestExporterAuth(t *testing.T) {
2173
2167
})
2174
2168
err := exporter .Start (context .Background (), & mockHost {
2175
2169
extensions : map [component.ID ]component.Component {
2176
- testauthID : build (t , extensionauth .NewClient ,
2177
- extensionauth .WithClientRoundTripper (func (http.RoundTripper ) (http.RoundTripper , error ) {
2178
- return roundTripperFunc (func (* http.Request ) (* http.Response , error ) {
2179
- select {
2180
- case done <- struct {}{}:
2181
- default :
2182
- }
2183
- return nil , errors .New ("nope" )
2184
- }), nil
2185
- }),
2186
- ),
2170
+ testauthID : newMockAuthClient (func (* http.Request ) (* http.Response , error ) {
2171
+ select {
2172
+ case done <- struct {}{}:
2173
+ default :
2174
+ }
2175
+ return nil , errors .New ("nope" )
2176
+ }),
2187
2177
},
2188
2178
})
2189
2179
require .NoError (t , err )
@@ -2211,14 +2201,10 @@ func TestExporterBatcher(t *testing.T) {
2211
2201
})
2212
2202
err := exporter .Start (context .Background (), & mockHost {
2213
2203
extensions : map [component.ID ]component.Component {
2214
- testauthID : build (t , extensionauth .NewClient ,
2215
- extensionauth .WithClientRoundTripper (func (http.RoundTripper ) (http.RoundTripper , error ) {
2216
- return roundTripperFunc (func (req * http.Request ) (* http.Response , error ) {
2217
- requests = append (requests , req )
2218
- return nil , errors .New ("nope" )
2219
- }), nil
2220
- }),
2221
- ),
2204
+ testauthID : newMockAuthClient (func (req * http.Request ) (* http.Response , error ) {
2205
+ requests = append (requests , req )
2206
+ return nil , errors .New ("nope" )
2207
+ }),
2222
2208
},
2223
2209
})
2224
2210
require .NoError (t , err )
@@ -2396,6 +2382,23 @@ func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
2396
2382
return f (r )
2397
2383
}
2398
2384
2385
+ var (
2386
+ _ extension.Extension = (* mockAuthClient )(nil )
2387
+ _ extensionauth.HTTPClient = (* mockAuthClient )(nil )
2388
+ )
2389
+
2390
+ type mockAuthClient struct {
2391
+ component.StartFunc
2392
+ component.ShutdownFunc
2393
+ extensionauth.ClientRoundTripperFunc
2394
+ }
2395
+
2396
+ func newMockAuthClient (f func (* http.Request ) (* http.Response , error )) * mockAuthClient {
2397
+ return & mockAuthClient {ClientRoundTripperFunc : func (http.RoundTripper ) (http.RoundTripper , error ) {
2398
+ return roundTripperFunc (f ), nil
2399
+ }}
2400
+ }
2401
+
2399
2402
func actionJSONToIndex (t * testing.T , actionJSON json.RawMessage ) string {
2400
2403
t .Helper ()
2401
2404
return actionGetValue (t , actionJSON , "_index" )
0 commit comments