diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go index b4631fb22c0..62bcfa7e256 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/oconf/options_test.go @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go index c20869e60e8..137a81bc721 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/oconf/options_test.go @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyUrl, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go index 254d38bef49..0f71f23876d 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyUrl, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests { diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go index 91d59985286..8b92179b640 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyUrl, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyUrl.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests { diff --git a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl index abd12c80ca7..fae0d20a7c5 100644 --- a/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl @@ -19,6 +19,8 @@ package oconf import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -455,6 +457,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, metric.AggregationDrop{}, got(undefinedKind)) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Metrics.Proxy) + proxyURL, err := c.Metrics.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyURL.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Metrics.Proxy) + }, + }, } for _, tt := range tests { diff --git a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl index 8b614b0c47b..d0748c8582e 100644 --- a/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl @@ -19,6 +19,8 @@ package otlpconfig import ( "errors" + "net/http" + "net/url" "testing" "time" @@ -419,6 +421,29 @@ func TestConfigs(t *testing.T) { assert.Equal(t, c.Traces.Timeout, 5*time.Second) }, }, + + // Proxy Tests + { + name: "Test With Proxy", + opts: []GenericOption{ + WithProxyFunc(func(r *http.Request) (*url.URL, error) { + return url.Parse("http://proxy.com") + }), + }, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.NotNil(t, c.Traces.Proxy) + proxyURL, err := c.Traces.Proxy(&http.Request{}) + assert.NoError(t, err) + assert.Equal(t, "http://proxy.com", proxyURL.String()) + }, + }, + { + name: "Test Without Proxy", + opts: []GenericOption{}, + asserts: func(t *testing.T, c *Config, grpcOption bool) { + assert.Nil(t, c.Traces.Proxy) + }, + }, } for _, tt := range tests {