Skip to content

Commit

Permalink
Merge pull request #13 from krakend/deepsource_suggested_improvements
Browse files Browse the repository at this point in the history
Deepsource suggested improvements
  • Loading branch information
kpacha authored Sep 17, 2024
2 parents 8d3b4f9 + ce308bf commit 78fa64e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 99 deletions.
52 changes: 30 additions & 22 deletions encode_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package audit

import (
"crypto/rand"
"fmt"
"math/rand"
"reflect"
"testing"
"time"

bf "github.com/krakendio/bloomfilter/v2/krakend"
botdetector "github.com/krakendio/krakend-botdetector/v2/krakend"
Expand All @@ -18,8 +19,15 @@ import (
server "github.com/luraproject/lura/v2/transport/http/server/plugin"
)

func intn(k int) int {
n, err := rand.Read(nil)
if err != nil {
return time.Now().Nanosecond() % k
}
return n % k
}

func TestMarshal(t *testing.T) {
rand.Seed(1)
result := Parse(generateCfg())

b, err := Marshal(&result)
Expand Down Expand Up @@ -88,56 +96,56 @@ func generateCfg() *config.ServiceConfig {
for i := 0; i < 1000; i++ {
var endpoints []*config.EndpointConfig

for k := 0; k < 1+rand.Intn(3); k++ {
for k := 0; k < 1+intn(3); k++ {
e := &config.EndpointConfig{
Endpoint: fmt.Sprintf("/foo/%3d", rand.Intn(100)),
Endpoint: fmt.Sprintf("/foo/%3d", intn(100)),
OutputEncoding: "json",
Backend: []*config.Backend{},
ExtraConfig: config.ExtraConfig{
fmt.Sprintf("component%3d", rand.Intn(100)): true,
fmt.Sprintf("component%3d", rand.Intn(100)): true,
plugin.Namespace: map[string]interface{}{},
proxy.Namespace: map[string]interface{}{},
fmt.Sprintf("component%3d", intn(100)): true,
fmt.Sprintf("component%3d", intn(100)): true,
plugin.Namespace: map[string]interface{}{},
proxy.Namespace: map[string]interface{}{},
},
}
for j := 0; j < 1+rand.Intn(5); j++ {
for j := 0; j < 1+intn(5); j++ {
e.Backend = append(e.Backend, &config.Backend{
URLPattern: fmt.Sprintf("/foo/%3d", rand.Intn(100)),
URLPattern: fmt.Sprintf("/foo/%3d", intn(100)),
Group: fmt.Sprintf("group-%3d", j),
AllowList: []string{"foo", "bar"},
Mapping: map[string]string{"foo": "foobar"},
Encoding: "json",
ExtraConfig: config.ExtraConfig{
fmt.Sprintf("component%3d", rand.Intn(100)): true,
fmt.Sprintf("component%3d", rand.Intn(100)): true,
client.Namespace: map[string]interface{}{},
fmt.Sprintf("component%3d", intn(100)): true,
fmt.Sprintf("component%3d", intn(100)): true,
client.Namespace: map[string]interface{}{},
},
})
}
endpoints = append(endpoints, e)
}
for k := 0; k < 1+rand.Intn(3); k++ {
for k := 0; k < 1+intn(3); k++ {
e := &config.EndpointConfig{
Endpoint: fmt.Sprintf("/foo/%3d", rand.Intn(100)),
Endpoint: fmt.Sprintf("/foo/%3d", intn(100)),
OutputEncoding: "no-op",
Backend: []*config.Backend{
{
URLPattern: fmt.Sprintf("/foo/%3d", rand.Intn(100)),
URLPattern: fmt.Sprintf("/foo/%3d", intn(100)),
Group: "first",
AllowList: []string{"foo", "bar"},
Mapping: map[string]string{"foo": "foobar"},
Encoding: "no-op",
ExtraConfig: config.ExtraConfig{
fmt.Sprintf("component%3d", rand.Intn(100)): true,
client.Namespace: map[string]interface{}{},
fmt.Sprintf("component%3d", intn(100)): true,
client.Namespace: map[string]interface{}{},
},
},
},
ExtraConfig: config.ExtraConfig{
fmt.Sprintf("component%3d", rand.Intn(100)): true,
fmt.Sprintf("component%3d", rand.Intn(100)): true,
plugin.Namespace: map[string]interface{}{},
proxy.Namespace: map[string]interface{}{},
fmt.Sprintf("component%3d", intn(100)): true,
fmt.Sprintf("component%3d", intn(100)): true,
plugin.Namespace: map[string]interface{}{},
proxy.Namespace: map[string]interface{}{},
},
}
endpoints = append(endpoints, e)
Expand Down
32 changes: 14 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/kms v1.15.5 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/PuerkitoBio/goquery v1.8.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/aws/aws-sdk-go v1.47.13 // indirect
Expand All @@ -55,29 +55,27 @@ require (
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-test/deep v1.1.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v5 v5.1.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
Expand All @@ -88,7 +86,6 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/krakend/go-auth0 v1.0.0 // indirect
github.com/krakendio/flatmap v1.1.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
Expand All @@ -101,10 +98,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/tmthrgd/atomics v0.0.0-20190904060638-dc7a5fcc7e0d // indirect
Expand All @@ -122,12 +118,12 @@ require (
gocloud.dev v0.34.0 // indirect
gocloud.dev/secrets/hashivault v0.34.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.151.0 // indirect
Expand Down
Loading

0 comments on commit 78fa64e

Please sign in to comment.