Skip to content

Commit

Permalink
[chore] update tests to expect default config to be present when test…
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Aug 9, 2024
1 parent 52ac35e commit 19ea8dd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
50 changes: 29 additions & 21 deletions exporter/elasticsearchexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func TestConfig(t *testing.T) {
Enabled: false,
},
Pipeline: "mypipeline",
ClientConfig: confighttp.ClientConfig{
Timeout: 2 * time.Minute,
MaxIdleConns: &defaultMaxIdleConns,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{
ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) {
cfg.Timeout = 2 * time.Minute
cfg.MaxIdleConns = &defaultMaxIdleConns
cfg.IdleConnTimeout = &defaultIdleConnTimeout
cfg.Headers = map[string]configopaque.String{
"myheader": "test",
},
},
}
}),
Authentication: AuthenticationSettings{
User: "elastic",
Password: "search",
Expand Down Expand Up @@ -143,14 +143,14 @@ func TestConfig(t *testing.T) {
Enabled: false,
},
Pipeline: "mypipeline",
ClientConfig: confighttp.ClientConfig{
Timeout: 2 * time.Minute,
MaxIdleConns: &defaultMaxIdleConns,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{
ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) {
cfg.Timeout = 2 * time.Minute
cfg.MaxIdleConns = &defaultMaxIdleConns
cfg.IdleConnTimeout = &defaultIdleConnTimeout
cfg.Headers = map[string]configopaque.String{
"myheader": "test",
},
},
}
}),
Authentication: AuthenticationSettings{
User: "elastic",
Password: "search",
Expand Down Expand Up @@ -213,14 +213,14 @@ func TestConfig(t *testing.T) {
Enabled: false,
},
Pipeline: "mypipeline",
ClientConfig: confighttp.ClientConfig{
Timeout: 2 * time.Minute,
MaxIdleConns: &defaultMaxIdleConns,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{
ClientConfig: withDefaultHTTPClientConfig(func(cfg *confighttp.ClientConfig) {
cfg.Timeout = 2 * time.Minute
cfg.MaxIdleConns = &defaultMaxIdleConns
cfg.IdleConnTimeout = &defaultIdleConnTimeout
cfg.Headers = map[string]configopaque.String{
"myheader": "test",
},
},
}
}),
Authentication: AuthenticationSettings{
User: "elastic",
Password: "search",
Expand Down Expand Up @@ -423,3 +423,11 @@ func withDefaultConfig(fns ...func(*Config)) *Config {
}
return cfg
}

func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig {
cfg := confighttp.NewDefaultClientConfig()
for _, fn := range fns {
fn(&cfg)
}
return cfg
}
26 changes: 17 additions & 9 deletions exporter/opensearchexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ func TestLoadConfig(t *testing.T) {
expected: &Config{
Dataset: "ngnix",
Namespace: "eu",
ClientConfig: confighttp.ClientConfig{
Endpoint: sampleEndpoint,
Timeout: 2 * time.Minute,
Headers: map[string]configopaque.String{
ClientConfig: withDefaultHTTPClientConfig(func(config *confighttp.ClientConfig) {
config.Endpoint = sampleEndpoint
config.Timeout = 2 * time.Minute
config.Headers = map[string]configopaque.String{
"myheader": "test",
},
MaxIdleConns: &maxIdleConns,
IdleConnTimeout: &idleConnTimeout,
Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("sample_basic_auth")},
},
}
config.MaxIdleConns = &maxIdleConns
config.IdleConnTimeout = &idleConnTimeout
config.Auth = &configauth.Authentication{AuthenticatorID: component.MustNewID("sample_basic_auth")}
}),
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
InitialInterval: 100 * time.Millisecond,
Expand Down Expand Up @@ -133,3 +133,11 @@ func withDefaultConfig(fns ...func(*Config)) *Config {
}
return cfg
}

func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig {
cfg := confighttp.NewDefaultClientConfig()
for _, fn := range fns {
fn(&cfg)
}
return cfg
}
26 changes: 17 additions & 9 deletions exporter/zipkinexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ func TestLoadConfig(t *testing.T) {
NumConsumers: 2,
QueueSize: 10,
},
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://somedest:1234/api/v2/spans",
WriteBufferSize: 524288,
Timeout: 5 * time.Second,
TLSSetting: configtls.ClientConfig{
ClientConfig: withDefaultHTTPClientConfig(func(config *confighttp.ClientConfig) {
config.Endpoint = "https://somedest:1234/api/v2/spans"
config.WriteBufferSize = 524288
config.Timeout = 5 * time.Second
config.TLSSetting = configtls.ClientConfig{
InsecureSkipVerify: true,
},
MaxIdleConns: &maxIdleConns,
IdleConnTimeout: &idleConnTimeout,
},
}
config.MaxIdleConns = &maxIdleConns
config.IdleConnTimeout = &idleConnTimeout
}),
Format: "proto",
DefaultServiceName: "test_name",
},
Expand All @@ -87,3 +87,11 @@ func TestLoadConfig(t *testing.T) {
})
}
}

func withDefaultHTTPClientConfig(fns ...func(config *confighttp.ClientConfig)) confighttp.ClientConfig {
cfg := confighttp.NewDefaultClientConfig()
for _, fn := range fns {
fn(&cfg)
}
return cfg
}

0 comments on commit 19ea8dd

Please sign in to comment.