Skip to content

Commit

Permalink
[UPDATE] Add unit test for utils file and refactoring ZeroLen function
Browse files Browse the repository at this point in the history
Signed-off-by: poyaz <pooya_azarpour@yahoo.com>
  • Loading branch information
poyaz committed Apr 11, 2024
1 parent 22de53e commit df889cb
Show file tree
Hide file tree
Showing 2 changed files with 603 additions and 3 deletions.
23 changes: 20 additions & 3 deletions operator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ func RandomStringGenerator(n int) string {
}

func ZeroLen(v interface{}) bool {
return v == nil ||
(reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil()) ||
(reflect.ValueOf(v).Kind() == reflect.Ptr && !reflect.ValueOf(v).IsNil() && reflect.ValueOf(v).Elem().Len() == 0)
if v == nil {
return true
}

vv := reflect.ValueOf(v)
if vv.Kind() == reflect.Ptr {
if vv.IsNil() {
return true
}
vv = vv.Elem()
}
if !(vv.IsValid() && !vv.IsZero()) {
return true
}
switch vv.Kind() {
case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:
return vv.Len() == 0
}

return true
}

func AppendTLSOptionsArgs(opts *k8upv1.TLSOptions, prefixArgName ...string) []string {
Expand Down
Loading

0 comments on commit df889cb

Please sign in to comment.