This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git
The following commit(s) were added to refs/heads/develop by this push:
new 1f7c7364 fix(tests): add NOSONAR comments to suppress sonar warnings
in test files (#734)
1f7c7364 is described below
commit 1f7c7364d47baa7567b762843e6ee39020be179e
Author: Xuetao Li <[email protected]>
AuthorDate: Wed Aug 13 19:33:13 2025 +0800
fix(tests): add NOSONAR comments to suppress sonar warnings in test files
(#734)
---
pkg/adapter/dubboregistry/registry/base/baseregistry_test.go | 2 +-
pkg/cluster/loadbalancer/rand/load_balancer_rand.go | 2 +-
pkg/filter/failinject/filter.go | 4 ++--
pkg/filter/http/loadbalancer/loadbalancer.go | 2 +-
pkg/filter/traffic/traffic.go | 2 +-
pkg/server/dynamic_resource_manager_test.go | 2 +-
pkg/server/listener_manager.go | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/pkg/adapter/dubboregistry/registry/base/baseregistry_test.go
b/pkg/adapter/dubboregistry/registry/base/baseregistry_test.go
index 72176d14..f051ceba 100644
--- a/pkg/adapter/dubboregistry/registry/base/baseregistry_test.go
+++ b/pkg/adapter/dubboregistry/registry/base/baseregistry_test.go
@@ -49,7 +49,7 @@ func CreateMockRegisteredAPI(urlPattern string) router.API {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]rune, n)
for i := range b {
- b[i] = letterRunes[rng.Intn(len(letterRunes))]
+ b[i] = letterRunes[rng.Intn(len(letterRunes))] //
NOSONAR
}
return string(b)
}
diff --git a/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
b/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
index 06417442..cfc493ae 100644
--- a/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
+++ b/pkg/cluster/loadbalancer/rand/load_balancer_rand.go
@@ -33,5 +33,5 @@ func init() {
type Rand struct{}
func (Rand) Handler(c *model.ClusterConfig, _ model.LbPolicy) *model.Endpoint {
- return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)]
+ return c.GetEndpoint(true)[rand.Intn(len(c.Endpoints)-1)] // NOSONAR
}
diff --git a/pkg/filter/failinject/filter.go b/pkg/filter/failinject/filter.go
index 460affe7..2c065e07 100644
--- a/pkg/filter/failinject/filter.go
+++ b/pkg/filter/failinject/filter.go
@@ -131,7 +131,7 @@ func (f Filter) match(rule *Rule) (matched bool) {
// random if the current request is matched
func random() bool {
- return (rand.Intn(1000)+1)%2 == 0
+ return (rand.Intn(1000)+1)%2 == 0 // NOSONAR
}
// percentage checks if the current request matches based on a given odds
percentage.
@@ -148,6 +148,6 @@ func percentage(odds int) bool {
return false
}
// generate rand number in 1-100
- num := rand.Intn(100) + 1
+ num := rand.Intn(100) + 1 // NOSONAR
return num <= odds
}
diff --git a/pkg/filter/http/loadbalancer/loadbalancer.go
b/pkg/filter/http/loadbalancer/loadbalancer.go
index fe057746..6bb0ac20 100644
--- a/pkg/filter/http/loadbalancer/loadbalancer.go
+++ b/pkg/filter/http/loadbalancer/loadbalancer.go
@@ -76,7 +76,7 @@ func (factory *FilterFactory) PrepareFilterChain(ctx
*contexthttp.HttpContext, c
func (f *Filter) Decode(c *contexthttp.HttpContext) filter.FilterStatus {
allInstances :=
strings.Split(c.GetAPI().IntegrationRequest.HTTPBackendConfig.URL, ",")
- idx := rand.Int31n(int32(len(allInstances)))
+ idx := rand.Int31n(int32(len(allInstances))) // NOSONAR
c.Api.IntegrationRequest.HTTPBackendConfig.URL =
strings.TrimSpace(allInstances[idx])
return filter.Continue
}
diff --git a/pkg/filter/traffic/traffic.go b/pkg/filter/traffic/traffic.go
index b1837b72..086371f9 100644
--- a/pkg/filter/traffic/traffic.go
+++ b/pkg/filter/traffic/traffic.go
@@ -180,7 +180,7 @@ func (f *Filter) trafficHeader(c *ClusterWrapper, ctx
*http.HttpContext) bool {
func (f *Filter) trafficWeight(c *ClusterWrapper) bool {
if f.weight == unInitialize {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
- f.weight = rng.Intn(100) + 1
+ f.weight = rng.Intn(100) + 1 // NOSONAR
}
return spiltWeight(f.weight, c.weightFloor, c.weightCeil)
diff --git a/pkg/server/dynamic_resource_manager_test.go
b/pkg/server/dynamic_resource_manager_test.go
index 7a5adbde..f0f8b433 100644
--- a/pkg/server/dynamic_resource_manager_test.go
+++ b/pkg/server/dynamic_resource_manager_test.go
@@ -194,7 +194,7 @@ func Test_createDynamicResourceManger(t *testing.T) {
err, _ = panicInfo.(error)
if err != nil {
fmt.Println(err)
- debug.PrintStack()
+ debug.PrintStack() // NOSONAR
}
}()
result = createDynamicResourceManger(tt.args.bs)
diff --git a/pkg/server/listener_manager.go b/pkg/server/listener_manager.go
index ff0371ef..b139c657 100644
--- a/pkg/server/listener_manager.go
+++ b/pkg/server/listener_manager.go
@@ -201,7 +201,7 @@ func (lm *ListenerManager) startListenerServiceAsync(s
listener.ListenerService)
panicErr := recover()
if panicErr != nil {
logger.Errorf("recover from panic %v", panicErr)
- debug.PrintStack()
+ debug.PrintStack() // NOSONAR
}
close(done)
}()