Skip to content

Commit

Permalink
refactor: internal/helper/image_unit_test : add name to table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PapePathe committed Oct 3, 2023
1 parent 32e335f commit 732dcd0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions golang/internal/helper/image/image_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

type RegistryTestCase struct {
Name string
Registry *string
RegistryUrl *string
ExpectedUrl string
Expand All @@ -23,36 +24,42 @@ type RegistryTestCase struct {
func TestRegistryWithTable(t *testing.T) {
testCases := []RegistryTestCase{
{
Name: "Test registry url",
Registry: pointer.NewPTR[string](""),
RegistryUrl: pointer.NewPTR[string]("test"),
ExpectedUrl: "test",
},
{
Name: "Test registry url priority",
Registry: pointer.NewPTR[string]("other"),
RegistryUrl: pointer.NewPTR[string]("test"),
ExpectedUrl: "test",
},
{
Name: "Test registry url empty",
Registry: nil,
RegistryUrl: nil,
ExpectedUrl: "",
},
{
Name: "Test registry url registry",
Registry: pointer.NewPTR[string]("other"),
RegistryUrl: nil,
ExpectedUrl: "other",
},
}

for _, tC := range testCases {
if tC.RegistryUrl == nil {
url := imageHelper.GetRegistryURL(tC.Registry, nil)
assert.Equal(t, url, tC.ExpectedUrl)
} else {
auth := &imageHelper.RegistryAuth{URL: *tC.RegistryUrl}
url := imageHelper.GetRegistryURL(tC.Registry, auth)
assert.Equal(t, url, tC.ExpectedUrl)
}
t.Run(tC.Name, func(t *testing.T) {
if tC.RegistryUrl == nil {
url := imageHelper.GetRegistryURL(tC.Registry, nil)
assert.Equal(t, url, tC.ExpectedUrl)
} else {
auth := &imageHelper.RegistryAuth{URL: *tC.RegistryUrl}
url := imageHelper.GetRegistryURL(tC.Registry, auth)
assert.Equal(t, url, tC.ExpectedUrl)
}
})
}
}

Expand Down

0 comments on commit 732dcd0

Please sign in to comment.