From e601ddaaa3b16d1f6969e5df16579267724fe9af Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 11:42:49 +0000 Subject: [PATCH 1/3] test: add pkg/id edge-case coverage pkg/id had no tests. Add edge-case coverage for SafeConcatName, SafeConcatNameMax (under/exact/over limit, trailing-dot strip, determinism), and ToDockerImageName (lowercasing, invalid-char strip, separators, empty). --- pkg/id/id_test.go | 108 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 pkg/id/id_test.go diff --git a/pkg/id/id_test.go b/pkg/id/id_test.go new file mode 100644 index 0000000000..347f8916b7 --- /dev/null +++ b/pkg/id/id_test.go @@ -0,0 +1,108 @@ +package id + +import ( + "strings" + "testing" +) + +func TestSafeConcatName(t *testing.T) { + tests := []struct { + name string + in []string + want string + }{ + {"single", []string{"foo"}, "foo"}, + {"multiple", []string{"foo", "bar", "baz"}, "foo-bar-baz"}, + {"empty parts joined", []string{"", "bar"}, "-bar"}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + if got := SafeConcatName(tc.in...); got != tc.want { + t.Fatalf("SafeConcatName(%v) = %q, want %q", tc.in, got, tc.want) + } + }) + } +} + +func TestSafeConcatNameMaxUnderLimit(t *testing.T) { + got := SafeConcatNameMax([]string{"foo", "bar"}, 63) + if got != "foo-bar" { + t.Fatalf("SafeConcatNameMax = %q, want %q", got, "foo-bar") + } +} + +func TestSafeConcatNameMaxExactLimit(t *testing.T) { + input := strings.Repeat("a", 63) + got := SafeConcatNameMax([]string{input}, 63) + if len(got) != 63 { + t.Fatalf("length = %d, want 63 (got %q)", len(got), got) + } + if got != input { + t.Fatalf("SafeConcatNameMax at limit = %q, want %q", got, input) + } +} + +func TestSafeConcatNameMaxOverLimit(t *testing.T) { + const maxLen = 63 + input := strings.Repeat("a", 100) + got := SafeConcatNameMax([]string{input}, maxLen) + if len(got) != maxLen { + t.Fatalf("length = %d, want %d (got %q)", len(got), maxLen, got) + } + if got[maxLen-8] != '-' { + t.Fatalf("expected hash separator at index %d, got %q", maxLen-8, got) + } + if got[:maxLen-8] != input[:maxLen-8] { + t.Fatalf("prefix not preserved: %q", got) + } +} + +func TestSafeConcatNameMaxStripsTrailingDot(t *testing.T) { + const maxLen = 63 + input := "a." + strings.Repeat("b", maxLen) + got := SafeConcatNameMax([]string{input}, maxLen) + if len(got) != maxLen { + t.Fatalf("length = %d, want %d (got %q)", len(got), maxLen, got) + } + if strings.Contains(got, ".-") { + t.Fatalf("expected trailing dot stripped, got %q", got) + } +} + +func TestSafeConcatNameMaxIsDeterministic(t *testing.T) { + input := strings.Repeat("x", 100) + first := SafeConcatNameMax([]string{input}, 63) + second := SafeConcatNameMax([]string{input}, 63) + if first != second { + t.Fatalf("not deterministic: %q != %q", first, second) + } +} + +func TestToDockerImageName(t *testing.T) { + tests := []struct { + name string + in string + want string + }{ + {"lowercases", "MyImage", "myimage"}, + {"strips invalid chars", "my.image:tag@special!", "myimagetagspecial"}, + {"keeps allowed separators", "my_image-name", "my_image-name"}, + {"empty stays empty", "", ""}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + if got := ToDockerImageName(tc.in); got != tc.want { + t.Fatalf("ToDockerImageName(%q) = %q, want %q", tc.in, got, tc.want) + } + }) + } +} + +func TestToDockerImageNameOnlyLowercase(t *testing.T) { + got := ToDockerImageName("ABC123") + for _, r := range got { + if r >= 'A' && r <= 'Z' { + t.Fatalf("result contains uppercase rune %q in %q", r, got) + } + } +} From 630f168042346b4bf092b0f96f318672ce5df2ba Mon Sep 17 00:00:00 2001 From: Samuel K Date: Wed, 12 Aug 2026 14:27:44 -0500 Subject: [PATCH 2/3] style: update constants --- pkg/id/id_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/id/id_test.go b/pkg/id/id_test.go index 347f8916b7..2fda730967 100644 --- a/pkg/id/id_test.go +++ b/pkg/id/id_test.go @@ -5,15 +5,21 @@ import ( "testing" ) +const ( + fooVal = "foo" + barVal = "bar" + +) + func TestSafeConcatName(t *testing.T) { tests := []struct { name string in []string want string }{ - {"single", []string{"foo"}, "foo"}, - {"multiple", []string{"foo", "bar", "baz"}, "foo-bar-baz"}, - {"empty parts joined", []string{"", "bar"}, "-bar"}, + {"single", []string{fooVal}, fooVal}, + {"multiple", []string{fooVal, barVal, "baz"}, "foo-bar-baz"}, + {"empty parts joined", []string{"", barVal}, "-bar"}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -25,7 +31,7 @@ func TestSafeConcatName(t *testing.T) { } func TestSafeConcatNameMaxUnderLimit(t *testing.T) { - got := SafeConcatNameMax([]string{"foo", "bar"}, 63) + got := SafeConcatNameMax([]string{fooVal, barVal}, 63) if got != "foo-bar" { t.Fatalf("SafeConcatNameMax = %q, want %q", got, "foo-bar") } From ab6d38cc68ed8508ece16b14ab48d4f6888cda09 Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Thu, 13 Aug 2026 16:38:53 +0000 Subject: [PATCH 3/3] style(id): fix test formatting for gci Remove the stray blank line inside the const block in id_test.go so gci reports the file as properly formatted. Lint fix only; no behavior change. This commit was created by an AI agent (OpenHands) on behalf of the user. --- pkg/id/id_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/id/id_test.go b/pkg/id/id_test.go index 2fda730967..2013913987 100644 --- a/pkg/id/id_test.go +++ b/pkg/id/id_test.go @@ -8,7 +8,6 @@ import ( const ( fooVal = "foo" barVal = "bar" - ) func TestSafeConcatName(t *testing.T) {