isZeroValue checks if a reflect.Value is the zero value for its type
(v reflect.Value)
| 352 | |
| 353 | // isZeroValue checks if a reflect.Value is the zero value for its type |
| 354 | func 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, |
no test coverage detected