Skip to content

Commit a6dc97c

Browse files
authored
fix: fix slice init length (#7731)
Initialize a slice with a capacity of len(nameToString) rather than initializing the length of this slice. Signed-off-by: huochexizhan <[email protected]>
1 parent 0a543d1 commit a6dc97c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

ratelimits/limit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestLoadAndParseOverrideLimits(t *testing.T) {
120120
// Burst cannot be 0.
121121
_, err = loadAndParseOverrideLimits("testdata/busted_override_burst_0.yml")
122122
test.AssertError(t, err, "single override limit with burst=0")
123-
test.Assert(t, !os.IsNotExist(err), "test file should exist")
123+
test.AssertContains(t, err.Error(), "invalid burst")
124124

125125
// Id cannot be empty.
126126
_, err = loadAndParseOverrideLimits("testdata/busted_override_empty_id.yml")
@@ -179,7 +179,7 @@ func TestLoadAndParseDefaultLimits(t *testing.T) {
179179
// Burst cannot be 0.
180180
_, err = loadAndParseDefaultLimits("testdata/busted_default_burst_0.yml")
181181
test.AssertError(t, err, "single default limit with burst=0")
182-
test.Assert(t, !os.IsNotExist(err), "test file should exist")
182+
test.AssertContains(t, err.Error(), "invalid burst")
183183

184184
// Name cannot be empty.
185185
_, err = loadAndParseDefaultLimits("testdata/busted_default_empty_name.yml")

ratelimits/names.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ var stringToName = func() map[string]Name {
251251

252252
// limitNames is a slice of all rate limit names.
253253
var limitNames = func() []string {
254-
names := make([]string, len(nameToString))
254+
names := make([]string, 0, len(nameToString))
255255
for _, v := range nameToString {
256256
names = append(names, v)
257257
}

0 commit comments

Comments
 (0)