@@ -14,8 +14,6 @@ import (
14
14
"gopkg.in/yaml.v3"
15
15
16
16
"go.opentelemetry.io/collector/confmap"
17
- "go.opentelemetry.io/collector/featuregate"
18
- "go.opentelemetry.io/collector/internal/featuregates"
19
17
)
20
18
21
19
func newConfig (yamlBytes []byte , factories Factories ) (* Config , error ) {
@@ -108,106 +106,3 @@ func TestConfigProviderFile(t *testing.T) {
108
106
109
107
assert .EqualValues (t , configNop , cfg )
110
108
}
111
-
112
- func TestGetConfmap (t * testing.T ) {
113
- uriLocation := "file:" + filepath .Join ("testdata" , "otelcol-nop.yaml" )
114
- fileProvider := newFakeProvider ("file" , func (_ context.Context , _ string , _ confmap.WatcherFunc ) (* confmap.Retrieved , error ) {
115
- return confmap .NewRetrieved (newConfFromFile (t , uriLocation [5 :]))
116
- })
117
- set := ConfigProviderSettings {
118
- ResolverSettings : confmap.ResolverSettings {
119
- URIs : []string {uriLocation },
120
- ProviderFactories : []confmap.ProviderFactory {fileProvider },
121
- },
122
- }
123
-
124
- configBytes , err := os .ReadFile (filepath .Join ("testdata" , "otelcol-nop.yaml" ))
125
- require .NoError (t , err )
126
-
127
- yamlMap := map [string ]any {}
128
- err = yaml .Unmarshal (configBytes , yamlMap )
129
- require .NoError (t , err )
130
-
131
- cp , err := NewConfigProvider (set )
132
- require .NoError (t , err )
133
-
134
- cmp , ok := cp .(ConfmapProvider )
135
- require .True (t , ok )
136
-
137
- cmap , err := cmp .GetConfmap (context .Background ())
138
- require .NoError (t , err )
139
-
140
- assert .EqualValues (t , yamlMap , cmap .ToStringMap ())
141
- }
142
-
143
- func TestStrictlyTypedCoda (t * testing.T ) {
144
- tests := []struct {
145
- basename string
146
- // isErrFromStrictTypes indicates whether the test should expect an error when the feature gate is
147
- // disabled. If so, we check that it errs both with and without the feature gate and that the coda is never
148
- // present.
149
- isErrFromStrictTypes bool
150
- }{
151
- {basename : "weak-implicit-bool-to-string.yaml" },
152
- {basename : "weak-implicit-int-to-string.yaml" },
153
- {basename : "weak-implicit-bool-to-int.yaml" },
154
- {basename : "weak-implicit-string-to-int.yaml" },
155
- {basename : "weak-implicit-int-to-bool.yaml" },
156
- {basename : "weak-implicit-string-to-bool.yaml" },
157
- {basename : "weak-empty-map-to-empty-array.yaml" },
158
- {basename : "weak-slice-of-maps-to-map.yaml" },
159
- {basename : "weak-single-element-to-slice.yaml" },
160
- {
161
- basename : "otelcol-invalid-components.yaml" ,
162
- isErrFromStrictTypes : true ,
163
- },
164
- }
165
-
166
- for _ , tt := range tests {
167
- t .Run (tt .basename , func (t * testing.T ) {
168
- filename := filepath .Join ("testdata" , tt .basename )
169
- uriLocation := "file:" + filename
170
- fileProvider := newFakeProvider ("file" , func (_ context.Context , _ string , _ confmap.WatcherFunc ) (* confmap.Retrieved , error ) {
171
- return confmap .NewRetrieved (newConfFromFile (t , filename ))
172
- })
173
- cp , err := NewConfigProvider (ConfigProviderSettings {
174
- ResolverSettings : confmap.ResolverSettings {
175
- URIs : []string {uriLocation },
176
- ProviderFactories : []confmap.ProviderFactory {fileProvider },
177
- },
178
- })
179
- require .NoError (t , err )
180
- factories , err := nopFactories ()
181
- require .NoError (t , err )
182
-
183
- // Save the previous value of the feature gate and restore it after the test.
184
- prev := featuregates .StrictlyTypedInputGate .IsEnabled ()
185
- defer func () {
186
- require .NoError (t , featuregate .GlobalRegistry ().Set (featuregates .StrictlyTypedInputID , prev ))
187
- }()
188
-
189
- // Ensure the error does not appear with the feature gate disabled.
190
- require .NoError (t , featuregate .GlobalRegistry ().Set (featuregates .StrictlyTypedInputID , false ))
191
- _ , errWeakTypes := cp .Get (context .Background (), factories )
192
- if tt .isErrFromStrictTypes {
193
- require .Error (t , errWeakTypes )
194
- // Ensure coda is **NOT** present.
195
- assert .NotContains (t , errWeakTypes .Error (), strictlyTypedMessageCoda )
196
- } else {
197
- require .NoError (t , errWeakTypes )
198
- }
199
-
200
- // Test with the feature gate enabled.
201
- require .NoError (t , featuregate .GlobalRegistry ().Set (featuregates .StrictlyTypedInputID , true ))
202
- _ , errStrictTypes := cp .Get (context .Background (), factories )
203
- require .Error (t , errStrictTypes )
204
- if tt .isErrFromStrictTypes {
205
- // Ensure coda is **NOT** present.
206
- assert .NotContains (t , errStrictTypes .Error (), strictlyTypedMessageCoda )
207
- } else {
208
- // Ensure coda is present.
209
- assert .ErrorContains (t , errStrictTypes , strictlyTypedMessageCoda )
210
- }
211
- })
212
- }
213
- }
0 commit comments