Skip to content

Commit 4f6fd4e

Browse files
authored
[chore][pkg/datadog] Make test more resilient (#49881)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Uses `Unmarshal` to make sure internal fields are set in test. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Relates to open-telemetry/opentelemetry-collector/pull/15308 <!--Authorship attestation. See AGENTS.md for details. AI agents must not check this box on behalf of the user; the human author must check it themselves before the PR is ready for review.--> #### Authorship - [x] I, a human, wrote this pull request description myself. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 68b58a3 commit 4f6fd4e

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

pkg/datadog/config/config_test.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,20 @@ func TestValidateConnectorComponentConfig(t *testing.T) {
295295
}
296296

297297
func TestUnmarshal(t *testing.T) {
298+
httpConfigs := map[string]any{
299+
"read_buffer_size": 100,
300+
"write_buffer_size": 200,
301+
"timeout": "10s",
302+
"max_idle_conns": 300,
303+
"max_idle_conns_per_host": 150,
304+
"max_conns_per_host": 250,
305+
"disable_keep_alives": true,
306+
"idle_conn_timeout": "30s",
307+
"tls": map[string]any{"insecure_skip_verify": true},
308+
}
309+
// Create confighttp.ClientConfig via unmarshaling to preserve internal state.
298310
cfgWithHTTPConfigs := CreateDefaultConfig().(*Config)
299-
idleConnTimeout := 30 * time.Second
300-
maxIdleConn := 300
301-
maxIdleConnPerHost := 150
302-
maxConnPerHost := 250
303-
cfgWithHTTPConfigs.ClientConfig.ReadBufferSize = 100
304-
cfgWithHTTPConfigs.ClientConfig.WriteBufferSize = 200
305-
cfgWithHTTPConfigs.ClientConfig.Timeout = 10 * time.Second
306-
cfgWithHTTPConfigs.ClientConfig.MaxIdleConns = maxIdleConn
307-
cfgWithHTTPConfigs.ClientConfig.MaxIdleConnsPerHost = maxIdleConnPerHost
308-
cfgWithHTTPConfigs.ClientConfig.MaxConnsPerHost = maxConnPerHost
309-
cfgWithHTTPConfigs.ClientConfig.IdleConnTimeout = idleConnTimeout
310-
cfgWithHTTPConfigs.ClientConfig.DisableKeepAlives = true
311-
cfgWithHTTPConfigs.ClientConfig.TLS.InsecureSkipVerify = true
311+
require.NoError(t, confmap.NewFromStringMap(httpConfigs).Unmarshal(&cfgWithHTTPConfigs.ClientConfig))
312312
cfgWithHTTPConfigs.warnings = nil
313313

314314
tests := []struct {
@@ -452,19 +452,9 @@ func TestUnmarshal(t *testing.T) {
452452
err: "\"metrics::sums::initial_cumulative_monotonic_value\" can only be configured when \"metrics::sums::cumulative_monotonic_mode\" is set to \"to_delta\"",
453453
},
454454
{
455-
name: "unmarshall confighttp client configs",
456-
configMap: confmap.NewFromStringMap(map[string]any{
457-
"read_buffer_size": 100,
458-
"write_buffer_size": 200,
459-
"timeout": "10s",
460-
"max_idle_conns": 300,
461-
"max_idle_conns_per_host": 150,
462-
"max_conns_per_host": 250,
463-
"disable_keep_alives": true,
464-
"idle_conn_timeout": "30s",
465-
"tls": map[string]any{"insecure_skip_verify": true},
466-
}),
467-
cfg: cfgWithHTTPConfigs,
455+
name: "unmarshall confighttp client configs",
456+
configMap: confmap.NewFromStringMap(httpConfigs),
457+
cfg: cfgWithHTTPConfigs,
468458
},
469459
}
470460

0 commit comments

Comments
 (0)