MCPcopy
hub / github.com/grafana/tempo / TestOverridesExtension_MarshalYAML

Function TestOverridesExtension_MarshalYAML

modules/overrides/extension_test.go:184–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestOverridesExtension_MarshalYAML(t *testing.T) {
185 t.Run("overrides", func(t *testing.T) {
186 resetRegistryForTesting(t)
187 get := RegisterExtension(&testExtension{})
188
189 fieldB := 3
190 o := Overrides{}
191 o.Ingestion.MaxLocalTracesPerUser = 1000
192 o.Extensions = map[string]any{
193 "test_extension": &testExtension{FieldA: "yaml_val", FieldB: &fieldB},
194 }
195
196 b, err := yaml.Marshal(&o)
197 require.NoError(t, err)
198
199 // The marshaled YAML must contain the nested extension key.
200 assert.Contains(t, string(b), "test_extension:")
201
202 // Round-trip: unmarshal recovers the extension (Overrides.UnmarshalYAML calls processExtensions).
203 var o2 Overrides
204 require.NoError(t, yaml.Unmarshal(b, &o2))
205
206 assert.Equal(t, 1000, o2.Ingestion.MaxLocalTracesPerUser)
207 ext := get(&o2)
208 require.NotNil(t, ext)
209 assert.Equal(t, "yaml_val", ext.FieldA)
210 assert.Equal(t, 3, *ext.FieldB)
211 })
212
213 t.Run("legacy overrides", func(t *testing.T) {
214 resetRegistryForTesting(t)
215 RegisterExtension(&testExtension{})
216
217 fieldB := 8
218 o := Overrides{}
219 o.Ingestion.MaxLocalTracesPerUser = 500
220 o.Extensions = map[string]any{
221 "test_extension": &testExtension{FieldA: "legacy_yaml", FieldB: &fieldB},
222 }
223 l := o.toLegacy()
224
225 b, err := yaml.Marshal(&l)
226 require.NoError(t, err)
227
228 // Flat keys must appear at the top level; nested key must not.
229 yamlStr := string(b)
230 assert.Contains(t, yamlStr, "test_extension_field_a:")
231 assert.NotContains(t, yamlStr, "test_extension:")
232 })
233}
234
235func TestOverridesExtension_UnmarshalYAML(t *testing.T) {
236 t.Run("overrides", func(t *testing.T) {

Callers

nothing calls this directly

Calls 7

toLegacyMethod · 0.95
resetRegistryForTestingFunction · 0.85
RegisterExtensionFunction · 0.85
MarshalMethod · 0.65
UnmarshalMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected