Skip to content

Commit

Permalink
util.Truncate add the values to the truncated after the excess is 0
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Matache <[email protected]>
  • Loading branch information
mmatache committed Dec 17, 2021
1 parent 1e9c2ad commit e846a5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/util/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func Truncate(format string, max int, values ...interface{}) string {
// we try to reduce the first string we find
for _, value := range values {
if excess == 0 {
// add the values to the truncated so no formatting issues are encountered
truncated = append(truncated, value)
continue
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/util/truncate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func TestTruncate(t *testing.T) {
expected: "4d96-11ea-b174-c85b7644b6b5-5d0c1e62-4d96-11ea-b174--collector",
cap: "first value gets dropped, second truncated",
},
{
format: "%s-%s-collector",
max: 63,
values: []interface{}{"4d96-11ea-b174-c85b7644b6b5-5d0c1e62-4d96-11ea-b174-c85b7644b6b5", "d0c1e62"},
expected: "4d96-11ea-b174-c85b7644b6b5-5d0c1e62-4d96-11e-d0c1e62-collector",
cap: "first value gets truncated, second added",
},
{
format: "%d-%s-collector",
max: 63,
Expand Down

0 comments on commit e846a5e

Please sign in to comment.