Skip to content

Commit

Permalink
test(ui): utils 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 20, 2024
1 parent 7abda83 commit acfbb10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 0 additions & 15 deletions ui/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,8 @@ import (
"fmt"
)

func IntPtrToZero(num *int) int {
if num == nil {
return 0
}
return *num
}

func toPtr[T any](constVar T) *T { return &constVar }

func toPtrOrNil[T comparable](comparable T) *T {
var zero T
if comparable == zero {
return nil
}
return &comparable
}

func UrlEncodeBytesPtrOrNil(b []byte) *string {
if b == nil || len(b) == 0 || isZeros(b) {
return nil
Expand Down
21 changes: 21 additions & 0 deletions ui/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package utils

import "testing"

func Test_Utils(t *testing.T) {
res := UrlEncodeBytesPtrOrNil(nil)
if res != nil {
t.Error("UrlEncodeBytesPtrOrNil was not nil")
}

zeros := isZeros([]byte(""))
if !zeros {
t.Error("isZeros was not true")
}
val := 5
str := StrOrNA(&val)
if str != "5" {
t.Error("StrOrNA was not 5")
}

}

0 comments on commit acfbb10

Please sign in to comment.