From e846a5e02c16bb72b47ea347d01bf0c3f438ea0e Mon Sep 17 00:00:00 2001 From: Mihai Matache Date: Fri, 17 Dec 2021 12:23:02 +0200 Subject: [PATCH] util.Truncate add the values to the truncated after the excess is 0 Signed-off-by: Mihai Matache --- pkg/util/truncate.go | 2 ++ pkg/util/truncate_test.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/util/truncate.go b/pkg/util/truncate.go index 60c0b5cd9..cab1ff1f1 100644 --- a/pkg/util/truncate.go +++ b/pkg/util/truncate.go @@ -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 } diff --git a/pkg/util/truncate_test.go b/pkg/util/truncate_test.go index 2c957cad9..11af5a57c 100644 --- a/pkg/util/truncate_test.go +++ b/pkg/util/truncate_test.go @@ -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,