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

Function isZeroValue

modules/overrides/config_test.go:354–384  ·  view source on GitHub ↗

isZeroValue checks if a reflect.Value is the zero value for its type

(v reflect.Value)

Source from the content-addressed store, hash-verified

352
353// isZeroValue checks if a reflect.Value is the zero value for its type
354func isZeroValue(v reflect.Value) bool {
355 // Handle nil interfaces and pointers
356 if (v.Kind() == reflect.Interface || v.Kind() == reflect.Ptr) && v.IsNil() {
357 return true
358 }
359
360 // Special case for slices and maps
361 if (v.Kind() == reflect.Slice || v.Kind() == reflect.Map) && v.Len() == 0 {
362 return true
363 }
364
365 // For structs, recursively check fields
366 if v.Kind() == reflect.Struct {
367 if v.NumField() == 0 {
368 return true
369 }
370
371 allZero := true
372 for i := 0; i < v.NumField(); i++ {
373 if !isZeroValue(v.Field(i)) {
374 allZero = false
375 break
376 }
377 }
378 return allZero
379 }
380
381 // For other types, compare with zero value of that type
382 zeroValue := reflect.Zero(v.Type()).Interface()
383 return reflect.DeepEqual(v.Interface(), zeroValue)
384}
385
386// generateTestLegacyOverrides creates a test fixture with predefined values
387// If a new field is added to LegacyOverrides, it must be added here as well,

Callers 1

ensureAllFieldsPopulatedFunction · 0.85

Calls 3

KindMethod · 0.80
IsNilMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected