Skip to content

Commit

Permalink
chore: use default confighttp client for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll committed Dec 4, 2024
1 parent 67ba7b7 commit d866f0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
28 changes: 12 additions & 16 deletions exporter/alertmanagerexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package alertmanagerexporter

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -24,7 +23,6 @@ import (
)

func TestLoadConfig(t *testing.T) {
defaultTransport := http.DefaultTransport.(*http.Transport)
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -63,26 +61,24 @@ func TestLoadConfig(t *testing.T) {
NumConsumers: 2,
QueueSize: 10,
},
ClientConfig: confighttp.ClientConfig{
Headers: map[string]configopaque.String{
ClientConfig: func() confighttp.ClientConfig {
client := confighttp.NewDefaultClientConfig()
client.Headers = map[string]configopaque.String{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
"header1": "234",
"another": "somevalue",
},
Endpoint: "a.new.alertmanager.target:9093",
TLSSetting: configtls.ClientConfig{
}
client.Endpoint = "a.new.alertmanager.target:9093"
client.TLSSetting = configtls.ClientConfig{
Config: configtls.Config{
CAFile: "/var/lib/mycert.pem",
},
},
ReadBufferSize: 0,
WriteBufferSize: 524288,
Timeout: time.Second * 10,
MaxIdleConns: &defaultTransport.MaxIdleConns,
MaxIdleConnsPerHost: &defaultTransport.MaxIdleConnsPerHost,
MaxConnsPerHost: &defaultTransport.MaxConnsPerHost,
IdleConnTimeout: &defaultTransport.IdleConnTimeout,
},
}
client.ReadBufferSize = 0
client.WriteBufferSize = 524288
client.Timeout = time.Second * 10
return client
}(),
},
},
}
Expand Down
22 changes: 7 additions & 15 deletions receiver/elasticsearchreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package elasticsearchreceiver

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -140,11 +139,6 @@ func TestValidateEndpoint(t *testing.T) {
}

func TestLoadConfig(t *testing.T) {
defaultMaxIdleConns := http.DefaultTransport.(*http.Transport).MaxIdleConns
defaultMaxIdleConnsPerHost := http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost
defaultIdleConnTimeout := http.DefaultTransport.(*http.Transport).IdleConnTimeout

t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand Down Expand Up @@ -173,15 +167,13 @@ func TestLoadConfig(t *testing.T) {
MetricsBuilderConfig: defaultMetrics,
Username: "otel",
Password: "password",
ClientConfig: confighttp.ClientConfig{
Timeout: 10000000000,
Endpoint: "http://example.com:9200",
Headers: map[string]configopaque.String{},
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
ClientConfig: func() confighttp.ClientConfig {
client := confighttp.NewDefaultClientConfig()
client.Timeout = 10000000000
client.Endpoint = "http://example.com:9200"
client.Headers = map[string]configopaque.String{}
return client
}(),
},
},
}
Expand Down

0 comments on commit d866f0d

Please sign in to comment.