normalize normalizes the default value of fields to a uniform format, for example, a list with a length of 0 is normalized to nil. The purpose is making the object easily to be compared by reflect.DeepEqual.
(obj client.Object)
| 802 | // normalize normalizes the default value of fields to a uniform format, for example, a list with a length of 0 is normalized to nil. |
| 803 | // The purpose is making the object easily to be compared by reflect.DeepEqual. |
| 804 | func normalize(obj client.Object) (client.Object, error) { |
| 805 | if obj == nil { |
| 806 | return nil, nil |
| 807 | } |
| 808 | data, err := json.Marshal(obj) |
| 809 | if err != nil { |
| 810 | return nil, err |
| 811 | } |
| 812 | t := reflect.TypeOf(obj) |
| 813 | if t.Kind() == reflect.Ptr { |
| 814 | t = t.Elem() |
| 815 | } |
| 816 | newObj := reflect.New(t).Interface().(client.Object) |
| 817 | err = json.Unmarshal(data, newObj) |
| 818 | if err != nil { |
| 819 | return nil, err |
| 820 | } |
| 821 | return newObj, nil |
| 822 | } |
no test coverage detected
searching dependent graphs…