From 6c32ff048afebabbfbf639e11a92ef04a909982f Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Fri, 30 Jul 2021 14:47:04 +0200 Subject: [PATCH] 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 --- internal/common/pointers.go | 4 ++++ internal/common/pointers_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/internal/common/pointers.go b/internal/common/pointers.go index 2ba12ad12..c11ea4d11 100644 --- a/internal/common/pointers.go +++ b/internal/common/pointers.go @@ -11,3 +11,7 @@ func Uint64ToPtr(x uint64) *uint64 { func BoolToPtr(x bool) *bool { return &x } + +func StringToPtr(x string) *string { + return &x +} diff --git a/internal/common/pointers_test.go b/internal/common/pointers_test.go index 01c1d0cd8..c0af2d347 100644 --- a/internal/common/pointers_test.go +++ b/internal/common/pointers_test.go @@ -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) +}