@@ -29,6 +29,7 @@ import (
2929 "go.opentelemetry.io/collector/exporter/exporterbatcher"
3030 "go.opentelemetry.io/collector/exporter/exportertest"
3131 "go.opentelemetry.io/collector/exporter/xexporter"
32+ "go.opentelemetry.io/collector/extension"
3233 "go.opentelemetry.io/collector/extension/extensionauth"
3334 "go.opentelemetry.io/collector/pdata/pcommon"
3435 "go.opentelemetry.io/collector/pdata/plog"
@@ -41,13 +42,6 @@ import (
4142 "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/metadata"
4243)
4344
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-
5145func TestExporterLogs (t * testing.T ) {
5246 t .Run ("publish with success" , func (t * testing.T ) {
5347 rec := newBulkRecorder ()
@@ -2173,17 +2167,13 @@ func TestExporterAuth(t *testing.T) {
21732167 })
21742168 err := exporter .Start (context .Background (), & mockHost {
21752169 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+ }),
21872177 },
21882178 })
21892179 require .NoError (t , err )
@@ -2211,14 +2201,10 @@ func TestExporterBatcher(t *testing.T) {
22112201 })
22122202 err := exporter .Start (context .Background (), & mockHost {
22132203 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+ }),
22222208 },
22232209 })
22242210 require .NoError (t , err )
@@ -2396,6 +2382,23 @@ func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {
23962382 return f (r )
23972383}
23982384
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+
23992402func actionJSONToIndex (t * testing.T , actionJSON json.RawMessage ) string {
24002403 t .Helper ()
24012404 return actionGetValue (t , actionJSON , "_index" )
0 commit comments