Skip to content

Commit dbfc861

Browse files
Merge pull request #122 from gpb88/ocm-18954
OCM-18954 | feat: Move GetBoolNotNil function to ocm-common
2 parents 01b937e + c42cb6b commit dbfc861

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/utils/utils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package utils
22

33
import (
4-
"github.com/openshift-online/ocm-common/pkg/log"
54
"math/rand"
65
"time"
6+
7+
"github.com/openshift-online/ocm-common/pkg/log"
78
)
89

910
var r *rand.Rand
@@ -70,6 +71,10 @@ func GeneratePassword(length int) string {
7071
return string(password)
7172
}
7273

74+
func GetBoolNotNil(f *bool) bool {
75+
return f != nil && *f
76+
}
77+
7378
func randInt(max int) int {
7479
return rand.Intn(max)
7580
}

pkg/utils/utils_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,17 @@ var _ = Describe("Utils", func() {
4040
Expect(smallerThanByteInLength).To(Equal(truncated + "a"))
4141
})
4242
})
43+
var _ = Describe("Validates GetBoolNotNil function", func() {
44+
boolPtr := func(b bool) *bool { return &b }
45+
46+
DescribeTable("returns correct boolean value",
47+
func(input *bool, expected bool) {
48+
result := GetBoolNotNil(input)
49+
Expect(result).To(Equal(expected))
50+
},
51+
Entry("nil pointer returns false", nil, false),
52+
Entry("pointer to true returns true", boolPtr(true), true),
53+
Entry("pointer to false returns false", boolPtr(false), false),
54+
)
55+
})
4356
})

0 commit comments

Comments
 (0)