internal/common: add function to get a pointer to string literal

Add a new helper function to get a pointer to a string literal.

Add unit test for the new function.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-07-30 14:47:04 +02:00 committed by Ondřej Budai
parent 52ccf1d6ef
commit 6c32ff048a
2 changed files with 16 additions and 0 deletions

View file

@ -11,3 +11,7 @@ func Uint64ToPtr(x uint64) *uint64 {
func BoolToPtr(x bool) *bool {
return &x
}
func StringToPtr(x string) *string {
return &x
}

View file

@ -17,3 +17,15 @@ func TestBoolToPtr(t *testing.T) {
got := BoolToPtr(value)
assert.Equal(t, value, *got)
}
func TestUint64ToPtr(t *testing.T) {
var value uint64 = 1
got := Uint64ToPtr(value)
assert.Equal(t, value, *got)
}
func TestStringToPtr(t *testing.T) {
var value string = "the-greatest-test-value"
got := StringToPtr(value)
assert.Equal(t, value, *got)
}