Skip to content

Commit

Permalink
refactor internal/helper/image/image_unit_test.go extract utility fun…
Browse files Browse the repository at this point in the history
…ction

Promot NewPTR as a general helper function .
  • Loading branch information
PapePathe committed Oct 3, 2023
1 parent b5239d4 commit 32e335f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 6 additions & 9 deletions golang/internal/helper/image/image_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"

imageHelper "github.com/dyrector-io/dyrectorio/golang/internal/helper/image"
"github.com/dyrector-io/dyrectorio/golang/internal/pointer"
"github.com/dyrector-io/dyrectorio/protobuf/go/agent"
)

Expand All @@ -19,20 +20,16 @@ type RegistryTestCase struct {
ExpectedUrl string
}

func NewPTR[T any](value T) *T {
return &value
}

func TestRegistryWithTable(t *testing.T) {
testCases := []RegistryTestCase{
{
Registry: NewPTR[string](""),
RegistryUrl: NewPTR[string]("test"),
Registry: pointer.NewPTR[string](""),
RegistryUrl: pointer.NewPTR[string]("test"),
ExpectedUrl: "test",
},
{
Registry: NewPTR[string]("other"),
RegistryUrl: NewPTR[string]("test"),
Registry: pointer.NewPTR[string]("other"),
RegistryUrl: pointer.NewPTR[string]("test"),
ExpectedUrl: "test",
},
{
Expand All @@ -41,7 +38,7 @@ func TestRegistryWithTable(t *testing.T) {
ExpectedUrl: "",
},
{
Registry: NewPTR[string]("other"),
Registry: pointer.NewPTR[string]("other"),
RegistryUrl: nil,
ExpectedUrl: "other",
},
Expand Down
8 changes: 8 additions & 0 deletions golang/internal/pointer/pointer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pointer

/*
* Creates a new pointer of type T
*/
func NewPTR[T any](value T) *T {
return &value
}

0 comments on commit 32e335f

Please sign in to comment.