types: make CheckTarget.String() unambiguous by always emitting all fields

The previous implementation skipped empty fields, which meant targets
differing only in which fields were populated could produce the same
string (e.g. {UserId:"A"} and {DomainId:"A"} both gave "A"). This
caused key collisions when the string was used in storage index keys.
This commit is contained in:
nemunaire 2026-04-15 19:54:15 +07:00
commit 6493589bb4
2 changed files with 10 additions and 16 deletions

View file

@ -148,10 +148,13 @@ func TestCheckTarget_String(t *testing.T) {
target CheckTarget
want string
}{
{CheckTarget{}, ""},
{CheckTarget{UserId: "u1"}, "u1"},
{CheckTarget{UserId: "u1", DomainId: "d1"}, "u1/d1"},
{CheckTarget{}, "//"},
{CheckTarget{UserId: "u1"}, "u1//"},
{CheckTarget{UserId: "u1", DomainId: "d1"}, "u1/d1/"},
{CheckTarget{UserId: "u1", DomainId: "d1", ServiceId: "s1"}, "u1/d1/s1"},
// Ensure different targets with different empty fields don't collide.
{CheckTarget{DomainId: "d1"}, "/d1/"},
{CheckTarget{ServiceId: "s1"}, "//s1"},
}
for _, tt := range tests {
if got := tt.target.String(); got != tt.want {