Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/operator-controller/rukpak/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
const maxNameLength = 63

func ObjectNameForBaseAndSuffix(base string, suffix string) string {
if len(base)+len(suffix) > maxNameLength {
// Account for the "-" separator when checking the length.
if len(base)+len(suffix)+1 > maxNameLength {
base = base[:maxNameLength-len(suffix)-1]
}
return fmt.Sprintf("%s-%s", base, suffix)
Expand Down
35 changes: 32 additions & 3 deletions internal/operator-controller/rukpak/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,38 @@ import (
)

func Test_ObjectNameForBaseAndSuffix(t *testing.T) {
name := util.ObjectNameForBaseAndSuffix("my.object.thing.has.a.really.really.really.really.really.long.name", "suffix")
require.Len(t, name, 63)
require.Equal(t, "my.object.thing.has.a.really.really.really.really.really-suffix", name)
for _, tc := range []struct {
name string
base string
suffix string
expected string
}{
{
name: "base and suffix add up to less than 63 characters",
base: strings.Repeat("a", 55),
suffix: "service",
expected: strings.Repeat("a", 55) + "-service",
},
{
// the "-" separator would push the name to 64 characters
name: "base and suffix add up to 63 characters",
base: strings.Repeat("a", 56),
suffix: "service",
expected: strings.Repeat("a", 55) + "-service",
},
{
name: "base and suffix add up to more than 63 characters",
base: "my.object.thing.has.a.really.really.really.really.really.long.name",
suffix: "suffix",
expected: "my.object.thing.has.a.really.really.really.really.really-suffix",
},
} {
t.Run(tc.name, func(t *testing.T) {
name := util.ObjectNameForBaseAndSuffix(tc.base, tc.suffix)
require.Equal(t, tc.expected, name)
require.LessOrEqual(t, len(name), 63)
})
}
}

func TestMergeMaps(t *testing.T) {
Expand Down
Loading