Skip to content

Commit

Permalink
add tests for new proxy configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelAlliel committed Feb 11, 2024
1 parent 9c8288e commit 147b4eb
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package oconf

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package oconf

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package otlpconfig

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package otlpconfig

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package oconf

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package otlpconfig

import (
"errors"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 147b4eb

Please sign in to comment.