From 5a307d3dce91969f7da6ca96400b6a39f9b65d02 Mon Sep 17 00:00:00 2001 From: huochexizhan Date: Wed, 2 Oct 2024 00:08:32 +0800 Subject: [PATCH] fix: fix slice init length Signed-off-by: huochexizhan --- ratelimits/limit_test.go | 4 ++-- ratelimits/names.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ratelimits/limit_test.go b/ratelimits/limit_test.go index a783e8ce6c5..dc9dc87f7ad 100644 --- a/ratelimits/limit_test.go +++ b/ratelimits/limit_test.go @@ -120,7 +120,7 @@ func TestLoadAndParseOverrideLimits(t *testing.T) { // Burst cannot be 0. _, err = loadAndParseOverrideLimits("testdata/busted_override_burst_0.yml") test.AssertError(t, err, "single override limit with burst=0") - test.Assert(t, !os.IsNotExist(err), "test file should exist") + test.AssertContains(t, err.Error(), "invalid burst") // Id cannot be empty. _, err = loadAndParseOverrideLimits("testdata/busted_override_empty_id.yml") @@ -179,7 +179,7 @@ func TestLoadAndParseDefaultLimits(t *testing.T) { // Burst cannot be 0. _, err = loadAndParseDefaultLimits("testdata/busted_default_burst_0.yml") test.AssertError(t, err, "single default limit with burst=0") - test.Assert(t, !os.IsNotExist(err), "test file should exist") + test.AssertContains(t, err.Error(), "invalid burst") // Name cannot be empty. _, err = loadAndParseDefaultLimits("testdata/busted_default_empty_name.yml") diff --git a/ratelimits/names.go b/ratelimits/names.go index c70f3953678..4495f863865 100644 --- a/ratelimits/names.go +++ b/ratelimits/names.go @@ -251,7 +251,7 @@ var stringToName = func() map[string]Name { // limitNames is a slice of all rate limit names. var limitNames = func() []string { - names := make([]string, len(nameToString)) + names := make([]string, 0, len(nameToString)) for _, v := range nameToString { names = append(names, v) }