Files
Evan BradleyandGitHub 6bd15fd927 [confignet] Add omitempty tags to fields (#12302)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Adds `omitempty` to all struct fields that are not set with any of the
`NewDefault[...]` functions. If we like the approach here, I'll open PRs
for other config modules.

<!-- Issue number if applicable -->
#### Link to tracking issue

Works toward
https://github.com/open-telemetry/opentelemetry-collector/issues/12191

<!--Describe what testing was performed and which tests were added.-->
#### Testing

I added tests to check that this works when structs are marshaled with
confmap in a separate module so as not to create a direct dependency on
confmap within confignet.
2025-02-05 22:44:55 +00:00

29 lines
779 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/confmap"
)
func TestConfmapMarshalConfigNet(t *testing.T) {
conf := confmap.New()
require.NoError(t, conf.Marshal(confignet.NewDefaultDialerConfig()))
assert.Equal(t, map[string]any{}, conf.ToStringMap())
conf = confmap.New()
require.NoError(t, conf.Marshal(confignet.NewDefaultAddrConfig()))
assert.Equal(t, map[string]any{}, conf.ToStringMap())
conf = confmap.New()
require.NoError(t, conf.Marshal(confignet.NewDefaultTCPAddrConfig()))
assert.Equal(t, map[string]any{}, conf.ToStringMap())
}