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
5 changes: 2 additions & 3 deletions endpoint/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ func NewLabelsFromStringPlain(labelText string) (Labels, error) {
tokens := strings.Split(labelText, ",")
foundExternalDNSHeritage := false
for _, token := range tokens {
if len(strings.Split(token, "=")) != 2 {
key, val, ok := strings.Cut(token, "=")
if !ok {
continue
}
key := strings.Split(token, "=")[0]
val := strings.Split(token, "=")[1]
if key == "heritage" && val != heritage {
return nil, ErrInvalidHeritage
}
Expand Down
13 changes: 13 additions & 0 deletions endpoint/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ func (suite *LabelsSuite) TestDeserialize() {
suite.Nil(multipleHeritage, "if error should return nil")
}

func (suite *LabelsSuite) TestSerializeDeserializeWithEqualsInValue() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I would prefer using table-driven tests for this file, but I think that refactor is out of scope for this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be table driven test. As we need to make sure other cases of owner still supported.

Do not use suite. Name could be TestParseLabels or of similar semantic. the current
PR's test name (TestSerializeDeserializeWithEqualsInValue) is misleading precisely because it goes through the full round-trip to avoid writing the raw string by hand, masking that the bug is purely in parsing.

labels := Labels{
"owner": "team=platform",
"resource": "ingress/default/example",
}

serialized := labels.SerializePlain(false)
parsed, err := NewLabelsFromStringPlain(serialized)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests for actual label texts?

suite.NoError(err)
suite.Equal(labels, parsed)
}

func TestLabels(t *testing.T) {
suite.Run(t, new(LabelsSuite))
}