ensureAllFieldsPopulated checks that all fields in the struct have non-zero values This helps catch if a new field is added to LegacyOverrides but not included in our test fixture
(t *testing.T, o LegacyOverrides)
| 323 | // ensureAllFieldsPopulated checks that all fields in the struct have non-zero values |
| 324 | // This helps catch if a new field is added to LegacyOverrides but not included in our test fixture |
| 325 | func ensureAllFieldsPopulated(t *testing.T, o LegacyOverrides) { |
| 326 | v := reflect.ValueOf(o) |
| 327 | t.Helper() |
| 328 | |
| 329 | // Get the type of the struct |
| 330 | structType := v.Type() |
| 331 | |
| 332 | // Iterate through all fields |
| 333 | for i := 0; i < v.NumField(); i++ { |
| 334 | field := v.Field(i) |
| 335 | fieldName := structType.Field(i).Name |
| 336 | |
| 337 | // Skip certain fields that can be zero in valid configs |
| 338 | skip := []string{"IngestionArtificialDelay", "MetricsGeneratorSpanNameSanitization", "Extensions"} |
| 339 | if slices.Contains(skip, fieldName) { |
| 340 | continue |
| 341 | } |
| 342 | |
| 343 | // For bool fields, we consider that they're explicitly set |
| 344 | // regardless of whether they're true or false |
| 345 | if field.Kind() == reflect.Bool { |
| 346 | continue |
| 347 | } |
| 348 | |
| 349 | assert.False(t, isZeroValue(field), "Field %s has not been populated in the test fixture - add a value for it", fieldName) |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // isZeroValue checks if a reflect.Value is the zero value for its type |
| 354 | func isZeroValue(v reflect.Value) bool { |
no test coverage detected