Skip to content

Commit e756b2e

Browse files
ycombinatormergify[bot]
authored andcommitted
Bump up github.com/go-viper/mapstructure/v2 dependency (#8764)
* Bump up github.com/go-viper/mapstructure/v2 dependency * Update unit tests * Update unit tests (cherry picked from commit 676e18d) # Conflicts: # NOTICE-fips.txt # go.mod # go.sum # internal/pkg/otel/run_nofips_test.go
1 parent 352e9ef commit e756b2e

File tree

7 files changed

+87989
-9
lines changed

7 files changed

+87989
-9
lines changed

NOTICE-fips.txt

Lines changed: 87899 additions & 0 deletions
Large diffs are not rendered by default.

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,11 +3862,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38623862

38633863
--------------------------------------------------------------------------------
38643864
Dependency : github.com/go-viper/mapstructure/v2
3865-
Version: v2.2.1
3865+
Version: v2.3.0
38663866
Licence type (autodetected): MIT
38673867
--------------------------------------------------------------------------------
38683868

3869-
Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.2.1/LICENSE:
3869+
Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.3.0/LICENSE:
38703870

38713871
The MIT License (MIT)
38723872

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ require (
3131
github.com/elastic/opentelemetry-collector-components/processor/elastictraceprocessor v0.3.0
3232
github.com/elastic/opentelemetry-collector-components/processor/lsmintervalprocessor v0.3.0
3333
github.com/fatih/color v1.18.0
34+
<<<<<<< HEAD
3435
github.com/fsnotify/fsnotify v1.8.0
3536
github.com/go-viper/mapstructure/v2 v2.2.1
37+
=======
38+
github.com/fsnotify/fsnotify v1.9.0
39+
github.com/go-viper/mapstructure/v2 v2.3.0
40+
>>>>>>> 676e18de4 (Bump up github.com/go-viper/mapstructure/v2 dependency (#8764))
3641
github.com/gofrs/flock v0.12.1
3742
github.com/gofrs/uuid/v5 v5.2.0
3843
github.com/google/go-cmp v0.7.0

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,17 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
616616
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
617617
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
618618
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
619+
<<<<<<< HEAD
619620
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
620621
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
621622
github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg=
622623
github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
624+
=======
625+
github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
626+
github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
627+
github.com/go-zookeeper/zk v1.0.4 h1:DPzxraQx7OrPyXq2phlGlNSIyWEsAox0RJmjTseMV6I=
628+
github.com/go-zookeeper/zk v1.0.4/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
629+
>>>>>>> 676e18de4 (Bump up github.com/go-viper/mapstructure/v2 dependency (#8764))
623630
github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34HU=
624631
github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs=
625632
github.com/gobuffalo/packd v1.0.1 h1:U2wXfRr4E9DH8IdsDLlRFwTZTK7hLfq9qT/QHXGVe/0=
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
//go:build !requirefips
6+
7+
package otel
8+
9+
import (
10+
"context"
11+
"testing"
12+
"time"
13+
14+
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
16+
"go.opentelemetry.io/collector/otelcol"
17+
)
18+
19+
func TestStartCollector(t *testing.T) {
20+
testCases := []struct {
21+
configFile string
22+
expectedErrorMessage string
23+
}{
24+
{
25+
configFile: "all-components.yml",
26+
expectedErrorMessage: "", // empty string means no error is expected
27+
},
28+
{
29+
configFile: "nonexistent-component.yml",
30+
expectedErrorMessage: `'extensions' unknown type: "zpages"`,
31+
},
32+
}
33+
34+
for _, tc := range testCases {
35+
t.Run(tc.configFile, func(t *testing.T) {
36+
configFiles := getConfigFiles(tc.configFile)
37+
settings := NewSettings("test", configFiles)
38+
39+
collector, err := otelcol.NewCollector(*settings)
40+
require.NoError(t, err)
41+
require.NotNil(t, collector)
42+
43+
wg := startCollector(context.Background(), t, collector, tc.expectedErrorMessage)
44+
45+
if tc.expectedErrorMessage == "" {
46+
assert.Eventually(t, func() bool {
47+
return otelcol.StateRunning == collector.GetState()
48+
}, 10*time.Second, 200*time.Millisecond)
49+
}
50+
collector.Shutdown()
51+
wg.Wait()
52+
assert.Equal(t, otelcol.StateClosed, collector.GetState())
53+
})
54+
}
55+
}

pkg/component/component_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package component
66

77
import (
8-
"errors"
8+
"encoding/json"
99
"fmt"
1010
"os"
1111
"path/filepath"
@@ -16,15 +16,14 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/elastic/go-ucfg"
20-
2119
"github.com/elastic/elastic-agent-client/v7/pkg/client"
2220
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
2321
"github.com/elastic/elastic-agent-libs/logp"
24-
2522
"github.com/elastic/elastic-agent/internal/pkg/agent/transpiler"
2623
"github.com/elastic/elastic-agent/internal/pkg/eql"
24+
"github.com/elastic/go-ucfg"
2725

26+
"github.com/go-viper/mapstructure/v2"
2827
"github.com/google/go-cmp/cmp"
2928
"github.com/google/go-cmp/cmp/cmpopts"
3029
"google.golang.org/protobuf/types/known/structpb"
@@ -659,7 +658,7 @@ func TestToComponents(t *testing.T) {
659658
ID: "filestream-default-filestream-1",
660659
Type: client.UnitTypeInput,
661660
LogLevel: defaultUnitLogLevel,
662-
Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))),
661+
Err: fmt.Errorf("decoding error: %w", makeMapStructureErr(t)),
663662
},
664663
},
665664
},
@@ -747,7 +746,7 @@ func TestToComponents(t *testing.T) {
747746
ID: "cloudbeat-default-cloudbeat-1-unit",
748747
Type: client.UnitTypeInput,
749748
LogLevel: defaultUnitLogLevel,
750-
Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))),
749+
Err: fmt.Errorf("decoding error: %w", makeMapStructureErr(t)),
751750
},
752751
},
753752
},
@@ -2945,3 +2944,18 @@ func TestFlattenedDataStreamIsolatedUnits(t *testing.T) {
29452944
}
29462945
}
29472946
}
2947+
2948+
func makeMapStructureErr(t *testing.T) error {
2949+
t.Helper()
2950+
2951+
jsonStr := `{ "meta": [] }`
2952+
2953+
var data map[string]interface{}
2954+
err := json.Unmarshal([]byte(jsonStr), &data)
2955+
require.NoError(t, err)
2956+
2957+
var output struct {
2958+
Meta struct{} `mapstructure:"meta"`
2959+
}
2960+
return mapstructure.Decode(data, &output)
2961+
}

pkg/component/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestExpectedConfig(t *testing.T) {
183183
},
184184
},
185185
},
186-
Err: errors.New("decoding error: decoding failed due to the following error(s):\n\n'meta' expected a map, got 'slice'"),
186+
Err: errors.New("decoding error: decoding failed due to the following error(s):\n\n'meta' expected a map or struct, got \"slice\""),
187187
},
188188
}
189189

0 commit comments

Comments
 (0)