Skip to content

Commit

Permalink
fix:all groups are appended with RPC_REG_GROUP_SUFFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhua3 committed Jun 5, 2024
1 parent 13c3dc9 commit 353eea9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
12 changes: 1 addition & 11 deletions core/globalContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,11 @@ func (c *Context) parseRegGroupSuffix(urlMap map[string]*URL) {
if regGroupSuffix == "" {
return
}
filterMap := make(map[string]struct{}, len(urlMap))
for _, url := range urlMap {
filterMap[url.GetIdentityWithRegistry()] = struct{}{}
}
for k, url := range urlMap {
if strings.HasSuffix(url.Group, regGroupSuffix) {
continue
}
newUrl := url.Copy()
newUrl.Group += regGroupSuffix
if _, ok := filterMap[newUrl.GetIdentityWithRegistry()]; ok {
continue
}
filterMap[newUrl.GetIdentityWithRegistry()] = struct{}{}
urlMap[k] = newUrl
url.Group += regGroupSuffix
}
}

Expand Down
9 changes: 5 additions & 4 deletions core/globalContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,19 @@ func TestContext_parseRegGroupSuffix(t *testing.T) {
},
AssertFunc: func(t *testing.T, urlMap map[string]*URL) {
groupMap := countGroup(urlMap)
assert.Equal(t, 1, groupMap["group1"])
assert.Equal(t, 1, groupMap["group1"+regGroupSuffix])
assert.Equal(t, 0, groupMap["group1"])
assert.Equal(t, 2, groupMap["group1"+regGroupSuffix])
assert.Equal(t, 1, groupMap["group2"+regGroupSuffix])
assert.Equal(t, 1, groupMap["group3"])
assert.Equal(t, 1, groupMap["group3"+regGroupSuffix])
assert.Equal(t, 0, groupMap["group3"])
assert.Equal(t, 2, groupMap["group3"+regGroupSuffix])
assert.Equal(t, 2, groupMap["group4"+regGroupSuffix])
assert.Equal(t, 2, groupMap["group5"+regGroupSuffix])
},
},
}
os.Setenv(RegGroupSuffix, regGroupSuffix)
ctx := &Context{}
// replace all groups with regGroupSuffix
for _, s := range cases {
ctx.parseRegGroupSuffix(s.UrlMap)
s.AssertFunc(t, s.UrlMap)
Expand Down

0 comments on commit 353eea9

Please sign in to comment.