Skip to content

Commit 0261bad

Browse files
mackjmrAkhigbeEromo
authored andcommitted
[chore] [receiver/bigip] Use confighttp.NewDefaultClientConfig instead of manually creating struct (open-telemetry#35586)
**Description:** This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct. **Link to tracking Issue:** open-telemetry#35457
1 parent cc6917d commit 0261bad

File tree

5 files changed

+53
-53
lines changed

5 files changed

+53
-53
lines changed

receiver/bigipreceiver/client_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ const (
3838
)
3939

4040
func TestNewClient(t *testing.T) {
41+
clientConfig := confighttp.NewDefaultClientConfig()
42+
clientConfig.TLSSetting = configtls.ClientConfig{}
43+
clientConfig.Endpoint = defaultEndpoint
44+
45+
clientConfigNonExistentCA := confighttp.NewDefaultClientConfig()
46+
clientConfigNonExistentCA.Endpoint = defaultEndpoint
47+
clientConfigNonExistentCA.TLSSetting = configtls.ClientConfig{
48+
Config: configtls.Config{
49+
CAFile: "/non/existent",
50+
},
51+
}
52+
4153
testCase := []struct {
4254
desc string
4355
cfg *Config
@@ -49,14 +61,7 @@ func TestNewClient(t *testing.T) {
4961
{
5062
desc: "Invalid HTTP config",
5163
cfg: &Config{
52-
ClientConfig: confighttp.ClientConfig{
53-
Endpoint: defaultEndpoint,
54-
TLSSetting: configtls.ClientConfig{
55-
Config: configtls.Config{
56-
CAFile: "/non/existent",
57-
},
58-
},
59-
},
64+
ClientConfig: clientConfigNonExistentCA,
6065
},
6166
host: componenttest.NewNopHost(),
6267
settings: componenttest.NewNopTelemetrySettings(),
@@ -66,10 +71,7 @@ func TestNewClient(t *testing.T) {
6671
{
6772
desc: "Valid Configuration",
6873
cfg: &Config{
69-
ClientConfig: confighttp.ClientConfig{
70-
TLSSetting: configtls.ClientConfig{},
71-
Endpoint: defaultEndpoint,
72-
},
74+
ClientConfig: clientConfig,
7375
},
7476
host: componenttest.NewNopHost(),
7577
settings: componenttest.NewNopTelemetrySettings(),

receiver/bigipreceiver/config_test.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
)
2020

2121
func TestValidate(t *testing.T) {
22+
clientConfig := confighttp.NewDefaultClientConfig()
23+
clientConfig.Endpoint = defaultEndpoint
24+
25+
clientConfigInvalid := confighttp.NewDefaultClientConfig()
26+
clientConfigInvalid.Endpoint = "invalid://endpoint: 12efg"
2227
defaultConfig := createDefaultConfig().(*Config)
2328
defaultConfig.Username = "otelu"
2429
defaultConfig.Password = "otelp"
@@ -31,9 +36,7 @@ func TestValidate(t *testing.T) {
3136
{
3237
desc: "missing username, password, and invalid endpoint",
3338
cfg: &Config{
34-
ClientConfig: confighttp.ClientConfig{
35-
Endpoint: "invalid://endpoint: 12efg",
36-
},
39+
ClientConfig: clientConfigInvalid,
3740
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
3841
},
3942
expectedErr: multierr.Combine(
@@ -45,10 +48,9 @@ func TestValidate(t *testing.T) {
4548
{
4649
desc: "missing password and invalid endpoint",
4750
cfg: &Config{
48-
Username: "otelu",
49-
ClientConfig: confighttp.ClientConfig{
50-
Endpoint: "invalid://endpoint: 12efg",
51-
}, ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
51+
Username: "otelu",
52+
ClientConfig: clientConfigInvalid,
53+
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
5254
},
5355
expectedErr: multierr.Combine(
5456
errMissingPassword,
@@ -58,10 +60,8 @@ func TestValidate(t *testing.T) {
5860
{
5961
desc: "missing username and invalid endpoint",
6062
cfg: &Config{
61-
Password: "otelp",
62-
ClientConfig: confighttp.ClientConfig{
63-
Endpoint: "invalid://endpoint: 12efg",
64-
},
63+
Password: "otelp",
64+
ClientConfig: clientConfigInvalid,
6565
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
6666
},
6767
expectedErr: multierr.Combine(
@@ -72,11 +72,9 @@ func TestValidate(t *testing.T) {
7272
{
7373
desc: "invalid endpoint",
7474
cfg: &Config{
75-
Username: "otelu",
76-
Password: "otelp",
77-
ClientConfig: confighttp.ClientConfig{
78-
Endpoint: "invalid://endpoint: 12efg",
79-
},
75+
Username: "otelu",
76+
Password: "otelp",
77+
ClientConfig: clientConfigInvalid,
8078
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
8179
},
8280
expectedErr: multierr.Combine(
@@ -86,11 +84,9 @@ func TestValidate(t *testing.T) {
8684
{
8785
desc: "valid config",
8886
cfg: &Config{
89-
Username: "otelu",
90-
Password: "otelp",
91-
ClientConfig: confighttp.ClientConfig{
92-
Endpoint: defaultEndpoint,
93-
},
87+
Username: "otelu",
88+
Password: "otelp",
89+
ClientConfig: clientConfig,
9490
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
9591
},
9692
expectedErr: nil,

receiver/bigipreceiver/factory.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ func NewFactory() receiver.Factory {
2929

3030
// createDefaultConfig creates a config for Big-IP with as many default values as possible
3131
func createDefaultConfig() component.Config {
32+
clientConfig := confighttp.NewDefaultClientConfig()
33+
clientConfig.Endpoint = defaultEndpoint
34+
clientConfig.Timeout = 10 * time.Second
3235
return &Config{
3336
ControllerConfig: scraperhelper.ControllerConfig{
3437
CollectionInterval: 10 * time.Second,
3538
},
36-
ClientConfig: confighttp.ClientConfig{
37-
Endpoint: defaultEndpoint,
38-
Timeout: 10 * time.Second,
39-
},
39+
ClientConfig: clientConfig,
4040
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
4141
}
4242
}

receiver/bigipreceiver/factory_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
)
2020

2121
func TestNewFactory(t *testing.T) {
22+
clientConfig := confighttp.NewDefaultClientConfig()
23+
clientConfig.Endpoint = defaultEndpoint
24+
clientConfig.Timeout = 10 * time.Second
2225
testCases := []struct {
2326
desc string
2427
testFunc func(*testing.T)
@@ -39,10 +42,7 @@ func TestNewFactory(t *testing.T) {
3942
ControllerConfig: scraperhelper.ControllerConfig{
4043
CollectionInterval: 10 * time.Second,
4144
},
42-
ClientConfig: confighttp.ClientConfig{
43-
Endpoint: defaultEndpoint,
44-
Timeout: 10 * time.Second,
45-
},
45+
ClientConfig: clientConfig,
4646
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
4747
}
4848

receiver/bigipreceiver/scraper_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ import (
2727
)
2828

2929
func TestScraperStart(t *testing.T) {
30+
clientConfig := confighttp.NewDefaultClientConfig()
31+
clientConfig.TLSSetting = configtls.ClientConfig{}
32+
clientConfig.Endpoint = defaultEndpoint
33+
34+
clientConfigNonExistentCA := confighttp.NewDefaultClientConfig()
35+
clientConfigNonExistentCA.Endpoint = defaultEndpoint
36+
clientConfigNonExistentCA.TLSSetting = configtls.ClientConfig{
37+
Config: configtls.Config{
38+
CAFile: "/non/existent",
39+
},
40+
}
41+
3042
testcases := []struct {
3143
desc string
3244
scraper *bigipScraper
@@ -36,14 +48,7 @@ func TestScraperStart(t *testing.T) {
3648
desc: "Bad Config",
3749
scraper: &bigipScraper{
3850
cfg: &Config{
39-
ClientConfig: confighttp.ClientConfig{
40-
Endpoint: defaultEndpoint,
41-
TLSSetting: configtls.ClientConfig{
42-
Config: configtls.Config{
43-
CAFile: "/non/existent",
44-
},
45-
},
46-
},
51+
ClientConfig: clientConfigNonExistentCA,
4752
},
4853
settings: componenttest.NewNopTelemetrySettings(),
4954
},
@@ -53,10 +58,7 @@ func TestScraperStart(t *testing.T) {
5358
desc: "Valid Config",
5459
scraper: &bigipScraper{
5560
cfg: &Config{
56-
ClientConfig: confighttp.ClientConfig{
57-
TLSSetting: configtls.ClientConfig{},
58-
Endpoint: defaultEndpoint,
59-
},
61+
ClientConfig: clientConfig,
6062
},
6163
settings: componenttest.NewNopTelemetrySettings(),
6264
},

0 commit comments

Comments
 (0)