Files
telemetry/otelcol/unmarshaler_test.go
f3e9798c0d Update module github.com/go-viper/mapstructure/v2 to v2.5.0 (#14420)
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
|
[github.com/go-viper/mapstructure/v2](https://redirect.github.com/go-viper/mapstructure)
| `v2.4.0` → `v2.5.0` |
![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgo-viper%2fmapstructure%2fv2/v2.5.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgo-viper%2fmapstructure%2fv2/v2.4.0/v2.5.0?slim=true)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>go-viper/mapstructure
(github.com/go-viper/mapstructure/v2)</summary>

###
[`v2.5.0`](https://redirect.github.com/go-viper/mapstructure/releases/tag/v2.5.0)

[Compare
Source](https://redirect.github.com/go-viper/mapstructure/compare/v2.4.0...v2.5.0)

#### What's Changed

- Print qualified type name when ErrorUnused=true causes errors for
unused keys in embedded fields by
[@&#8203;jmacd](https://redirect.github.com/jmacd) in
[#&#8203;113](https://redirect.github.com/go-viper/mapstructure/pull/113)
- build(deps): bump github/codeql-action from 3.29.2 to 3.29.5 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;126](https://redirect.github.com/go-viper/mapstructure/pull/126)
- build(deps): bump github/codeql-action from 3.29.7 to 3.29.10 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;131](https://redirect.github.com/go-viper/mapstructure/pull/131)
- build(deps): bump actions/checkout from 4.2.2 to 5.0.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;129](https://redirect.github.com/go-viper/mapstructure/pull/129)
- feat: support for automatically initializing squashed pointer structs
by [@&#8203;tuunit](https://redirect.github.com/tuunit) in
[#&#8203;71](https://redirect.github.com/go-viper/mapstructure/pull/71)
- build(deps): bump actions/setup-go from 5.5.0 to 6.0.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;134](https://redirect.github.com/go-viper/mapstructure/pull/134)
- build(deps): bump ossf/scorecard-action from 2.4.2 to 2.4.3 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;142](https://redirect.github.com/go-viper/mapstructure/pull/142)
- Fix slice deep map (owned) by
[@&#8203;jphastings](https://redirect.github.com/jphastings) in
[#&#8203;144](https://redirect.github.com/go-viper/mapstructure/pull/144)
- chore: fix lint violations by
[@&#8203;sagikazarmark](https://redirect.github.com/sagikazarmark) in
[#&#8203;157](https://redirect.github.com/go-viper/mapstructure/pull/157)
- chore: switch to devenv by
[@&#8203;sagikazarmark](https://redirect.github.com/sagikazarmark) in
[#&#8203;158](https://redirect.github.com/go-viper/mapstructure/pull/158)
- build(deps): bump actions/upload-artifact from 4.6.2 to 5.0.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;151](https://redirect.github.com/go-viper/mapstructure/pull/151)
- build(deps): bump github/codeql-action from 3.29.10 to 4.31.2 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;153](https://redirect.github.com/go-viper/mapstructure/pull/153)
- build(deps): bump golangci/golangci-lint-action from 8.0.0 to 9.0.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;154](https://redirect.github.com/go-viper/mapstructure/pull/154)
- build(deps): bump actions/checkout from 5.0.0 to 6.0.1 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;160](https://redirect.github.com/go-viper/mapstructure/pull/160)
- build(deps): bump actions/setup-go from 6.0.0 to 6.1.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;159](https://redirect.github.com/go-viper/mapstructure/pull/159)
- build(deps): bump github/codeql-action from 4.31.7 to 4.31.8 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;162](https://redirect.github.com/go-viper/mapstructure/pull/162)
- build(deps): bump actions/upload-artifact from 5.0.0 to 6.0.0 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;161](https://redirect.github.com/go-viper/mapstructure/pull/161)
- build(deps): bump github/codeql-action from 4.31.8 to 4.31.9 by
[@&#8203;dependabot](https://redirect.github.com/dependabot)\[bot] in
[#&#8203;163](https://redirect.github.com/go-viper/mapstructure/pull/163)
- feature: Add map field name to convert structs dynamically instead of
individually with a tag. by
[@&#8203;thespags](https://redirect.github.com/thespags) in
[#&#8203;149](https://redirect.github.com/go-viper/mapstructure/pull/149)
- feat(decoder): support multiple tag names in order by
[@&#8203;DarkiT](https://redirect.github.com/DarkiT) in
[#&#8203;59](https://redirect.github.com/go-viper/mapstructure/pull/59)
- feat: optional root object name by
[@&#8203;andreev-fn](https://redirect.github.com/andreev-fn) in
[#&#8203;137](https://redirect.github.com/go-viper/mapstructure/pull/137)
- Add unmarshaler interface by
[@&#8203;sagikazarmark](https://redirect.github.com/sagikazarmark) in
[#&#8203;166](https://redirect.github.com/go-viper/mapstructure/pull/166)

#### New Contributors

- [@&#8203;jmacd](https://redirect.github.com/jmacd) made their first
contribution in
[#&#8203;113](https://redirect.github.com/go-viper/mapstructure/pull/113)
- [@&#8203;tuunit](https://redirect.github.com/tuunit) made their first
contribution in
[#&#8203;71](https://redirect.github.com/go-viper/mapstructure/pull/71)
- [@&#8203;jphastings](https://redirect.github.com/jphastings) made
their first contribution in
[#&#8203;144](https://redirect.github.com/go-viper/mapstructure/pull/144)
- [@&#8203;thespags](https://redirect.github.com/thespags) made their
first contribution in
[#&#8203;149](https://redirect.github.com/go-viper/mapstructure/pull/149)
- [@&#8203;DarkiT](https://redirect.github.com/DarkiT) made their first
contribution in
[#&#8203;59](https://redirect.github.com/go-viper/mapstructure/pull/59)
- [@&#8203;andreev-fn](https://redirect.github.com/andreev-fn) made
their first contribution in
[#&#8203;137](https://redirect.github.com/go-viper/mapstructure/pull/137)

**Full Changelog**:
<https://github.com/go-viper/mapstructure/compare/v2.4.0...v2.5.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi43NC41IiwidXBkYXRlZEluVmVyIjoiNDIuNzQuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGVib3QiXX0=-->

---------

Co-authored-by: Hanzo Dev <[email protected]>
Co-authored-by: otelbot <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
2026-01-15 16:20:16 +00:00

179 lines
4.4 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package otelcol
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/pipelines"
)
func TestUnmarshalEmpty(t *testing.T) {
factories, err := nopFactories()
require.NoError(t, err)
_, err = unmarshal(confmap.New(), factories)
assert.NoError(t, err)
}
func TestUnmarshalEmptyAllSections(t *testing.T) {
factories, err := nopFactories()
require.NoError(t, err)
conf := confmap.NewFromStringMap(map[string]any{
"receivers": nil,
"processors": nil,
"exporters": nil,
"connectors": nil,
"extensions": nil,
"service": nil,
})
cfg, err := unmarshal(conf, factories)
require.NoError(t, err)
assert.Equal(t, fakeTelemetryConfig{}, cfg.Service.Telemetry)
}
func TestUnmarshalUnknownTopLevel(t *testing.T) {
factories, err := nopFactories()
require.NoError(t, err)
conf := confmap.NewFromStringMap(map[string]any{
"unknown_section": nil,
})
_, err = unmarshal(conf, factories)
assert.ErrorContains(t, err, "has invalid keys: unknown_section")
}
func TestPipelineConfigUnmarshalError(t *testing.T) {
testCases := []struct {
// test case name (also file name containing config yaml)
name string
conf *confmap.Conf
// string that the error must contain
expectError string
}{
{
name: "duplicate-pipeline",
conf: confmap.NewFromStringMap(map[string]any{
"traces/ pipe": nil,
"traces /pipe": nil,
}),
expectError: "duplicate name",
},
{
name: "invalid-pipeline-name-after-slash",
conf: confmap.NewFromStringMap(map[string]any{
"metrics/": nil,
}),
expectError: "in \"metrics/\" id: the part after / should not be empty",
},
{
name: "invalid-pipeline-section",
conf: confmap.NewFromStringMap(map[string]any{
"traces": map[string]any{
"unknown_section": nil,
},
}),
expectError: "'[traces]' has invalid keys: unknown_section",
},
{
name: "invalid-pipeline-sub-config",
conf: confmap.NewFromStringMap(map[string]any{
"traces": "string",
}),
expectError: "'[traces]' expected a map or struct, got \"string\"",
},
{
name: "invalid-pipeline-type",
conf: confmap.NewFromStringMap(map[string]any{
"/metrics": nil,
}),
expectError: "in \"/metrics\" id: the part before / should not be empty",
},
{
name: "invalid-sequence-value",
conf: confmap.NewFromStringMap(map[string]any{
"traces": map[string]any{
"receivers": map[string]any{
"nop": map[string]any{
"some": "config",
},
},
},
}),
expectError: "'[traces].receivers' source data must be an array or slice, got map",
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
pips := new(pipelines.Config)
err := tt.conf.Unmarshal(&pips)
assert.ErrorContains(t, err, tt.expectError)
})
}
}
func TestServiceUnmarshalError(t *testing.T) {
testCases := []struct {
// test case name (also file name containing config yaml)
name string
conf *confmap.Conf
// string that the error must contain
expectError string
}{
{
name: "invalid-telemetry-unknown-key",
conf: confmap.NewFromStringMap(map[string]any{
"telemetry": map[string]any{
"unknown": "key",
},
}),
expectError: "decoding failed due to the following error(s):\n\n'telemetry' has invalid keys: unknown",
},
{
name: "invalid-service-extensions-section",
conf: confmap.NewFromStringMap(map[string]any{
"extensions": []any{
map[string]any{
"nop": map[string]any{
"some": "config",
},
},
},
}),
expectError: "'extensions[0]' has invalid keys: nop",
},
{
name: "invalid-service-section",
conf: confmap.NewFromStringMap(map[string]any{
"unknown_section": "string",
}),
expectError: "has invalid keys: unknown_section",
},
{
name: "invalid-pipelines-config",
conf: confmap.NewFromStringMap(map[string]any{
"pipelines": "string",
}),
expectError: "'pipelines' expected type 'pipelines.Config', got unconvertible type 'string'",
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
err := tt.conf.Unmarshal(&service.Config{
Telemetry: fakeTelemetryConfig{},
})
require.ErrorContains(t, err, tt.expectError)
})
}
}