Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/subsystem_test.go
5317 views
1
package integrations
2
3
import (
4
"testing"
5
6
v1 "github.com/grafana/agent/pkg/integrations"
7
"github.com/grafana/agent/pkg/integrations/v2/common"
8
"github.com/stretchr/testify/require"
9
"gopkg.in/yaml.v2"
10
)
11
12
func TestSubsystemOptions_Unmarshal(t *testing.T) {
13
setRegistered(t, map[Config]Type{
14
&testIntegrationA{}: TypeSingleton,
15
})
16
17
RegisterLegacy(&legacyConfig{}, TypeSingleton, func(in v1.Config, mc common.MetricsConfig) UpgradedConfig {
18
return &legacyShim{Data: in, Common: mc}
19
})
20
21
tt := []struct {
22
name string
23
in string
24
expectError string
25
}{
26
{
27
name: "invalid integration",
28
in: `
29
invalidintegration:
30
autoscrape:
31
enabled: true
32
`,
33
expectError: "line 2: field invalidintegration not found in type integrations.SubsystemOptions",
34
},
35
{
36
name: "invalid field",
37
in: `
38
test:
39
invalidfield: true
40
`,
41
expectError: "line 1: field invalidfield not found in type integrations.plain",
42
},
43
{
44
name: "invalid v1 field",
45
in: `
46
legacy:
47
invalidfield: true
48
`,
49
expectError: "line 1: field invalidfield not found",
50
},
51
}
52
53
for _, tc := range tt {
54
t.Run(tc.name, func(t *testing.T) {
55
var so SubsystemOptions
56
err := yaml.UnmarshalStrict([]byte(tc.in), &so)
57
58
var te *yaml.TypeError
59
require.ErrorAs(t, err, &te)
60
require.Len(t, te.Errors, 1)
61
require.Equal(t, tc.expectError, te.Errors[0])
62
})
63
}
64
}
65
66