Skip to content

Commit

Permalink
chore(server): unexport and rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
irenarindos authored and hugoghx committed Jan 7, 2025
1 parent 458de27 commit c116cd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/server/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (w *Worker) clone() *Worker {
// set over the API as well as the tags reported by the worker itself. This
// function is guaranteed to return a non-nil map.
func (w *Worker) CanonicalTags(opt ...Option) map[string][]string {
return DeduplicateTags(&w.ApiTags, &w.ConfigTags)
return compactTags(&w.ApiTags, &w.ConfigTags)
}

// GetConfigTags returns the tags for this worker which has been set through
Expand Down
10 changes: 5 additions & 5 deletions internal/server/worker_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ func (t *Tags) clone() Tags {
return newTags
}

// DeduplicateTags takes a list of Tags and returns a map of deduplicated tags
func DeduplicateTags(t ...*Tags) map[string][]string {
dedupedTags := make(map[Tag]struct{})
// compactTags takes a list of Tags and returns a map of deduplicated, compated tags
func compactTags(t ...*Tags) map[string][]string {
compactedTags := make(map[Tag]struct{})
for _, tags := range t {
for _, tag := range *tags {
dedupedTags[*tag] = struct{}{}
compactedTags[*tag] = struct{}{}
}
}

tags := make(map[string][]string)
for t := range dedupedTags {
for t := range compactedTags {
tags[t.Key] = append(tags[t.Key], t.Value)
}
return tags
Expand Down
2 changes: 1 addition & 1 deletion internal/server/worker_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestDeduplicateTags(t *testing.T) {
{Key: fmt.Sprintf("key-%d", pippo), Value: fmt.Sprintf("another-unique-%d", pippo)},
})
}
gotMap := DeduplicateTags(tags...)
gotMap := compactTags(tags...)
assert.Len(t, gotMap, 6)
assert.ElementsMatch(t, gotMap["key"], []string{"shared", "unique-0", "unique-1", "unique-2", "unique-3", "unique-4"})
assert.ElementsMatch(t, gotMap["key-0"], []string{"another-unique-0"})
Expand Down

0 comments on commit c116cd2

Please sign in to comment.