Skip to content

Commit

Permalink
馃毃 Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Aug 14, 2023
1 parent c59f665 commit 233cfd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
12 changes: 6 additions & 6 deletions backend/pkg/proto/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
RecordValue
)

type RegexProtoTopicMapping struct {
type regexProtoTopicMapping struct {
config.ProtoTopicMapping
r *regexp.Regexp
}
Expand All @@ -56,7 +56,7 @@ type Service struct {
logger *zap.Logger

strictMappingsByTopic map[string]config.ProtoTopicMapping
regexMappingsByTopic map[string]RegexProtoTopicMapping
regexMappingsByTopic map[string]regexProtoTopicMapping
gitSvc *git.Service
fsSvc *filesystem.Service
schemaSvc *schema.Service
Expand Down Expand Up @@ -132,9 +132,9 @@ func NewService(cfg config.Proto, logger *zap.Logger, schemaSvc *schema.Service)
}, nil
}

func setMappingsByTopic(mappings []config.ProtoTopicMapping) (strictMappingsByTopic map[string]config.ProtoTopicMapping, regexMappingsByTopic map[string]RegexProtoTopicMapping, err error) {
func setMappingsByTopic(mappings []config.ProtoTopicMapping) (strictMappingsByTopic map[string]config.ProtoTopicMapping, regexMappingsByTopic map[string]regexProtoTopicMapping, err error) {
strictMappingsByTopic = make(map[string]config.ProtoTopicMapping)
regexMappingsByTopic = make(map[string]RegexProtoTopicMapping)
regexMappingsByTopic = make(map[string]regexProtoTopicMapping)

for _, mapping := range mappings {
if mapping.IsRegex {
Expand All @@ -143,7 +143,7 @@ func setMappingsByTopic(mappings []config.ProtoTopicMapping) (strictMappingsByTo
return nil, nil, fmt.Errorf("invalid regexp as a topic name: %w", err)
}

regexMappingsByTopic[mapping.TopicName] = RegexProtoTopicMapping{
regexMappingsByTopic[mapping.TopicName] = regexProtoTopicMapping{
ProtoTopicMapping: mapping,
r: r,
}
Expand All @@ -152,7 +152,7 @@ func setMappingsByTopic(mappings []config.ProtoTopicMapping) (strictMappingsByTo
strictMappingsByTopic[mapping.TopicName] = mapping
}

return
return strictMappingsByTopic, regexMappingsByTopic, err
}

// Start polling the prototypes from the configured provider (e.g. filesystem or Git) and sync these
Expand Down
15 changes: 5 additions & 10 deletions backend/pkg/proto/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
"regexp"
"testing"

"github.com/redpanda-data/console/backend/pkg/config"
"github.com/stretchr/testify/assert"

"github.com/redpanda-data/console/backend/pkg/config"
)

func Test_decodeConfluentBinaryWrapper(t *testing.T) {
Expand Down Expand Up @@ -51,11 +52,6 @@ var (
IsRegex: false,
}

strictTopicMapping03 = config.ProtoTopicMapping{
TopicName: "strictTopicMapping03",
IsRegex: false,
}

regexTopicMapping01 = config.ProtoTopicMapping{
TopicName: "TopicName",
IsRegex: true,
Expand All @@ -77,7 +73,7 @@ func genNTopicMappings(n int, baseName string, isRegex bool) []config.ProtoTopic
func TestService_getMatchingMapping(t *testing.T) {
type fields struct {
strictMappingsByTopic map[string]config.ProtoTopicMapping
regexMappingsByTopic map[string]RegexProtoTopicMapping
regexMappingsByTopic map[string]regexProtoTopicMapping
}
type args struct {
topicName string
Expand Down Expand Up @@ -110,8 +106,8 @@ func TestService_getMatchingMapping(t *testing.T) {
strictTopicMapping02.TopicName: strictTopicMapping02,
regexTopicMapping01.TopicName: regexTopicMapping01,
},
regexMappingsByTopic: map[string]RegexProtoTopicMapping{
regexTopicMapping01.TopicName: RegexProtoTopicMapping{
regexMappingsByTopic: map[string]regexProtoTopicMapping{
regexTopicMapping01.TopicName: {
ProtoTopicMapping: regexTopicMapping01,
r: regexp.MustCompile(regexTopicMapping01.TopicName),
},
Expand Down Expand Up @@ -180,7 +176,6 @@ func BenchmarkService_getMatchingMapping(b *testing.B) {
}
for _, bench := range benchs {
b.Run(bench.name, func(b *testing.B) {

strictTopicMappings := genNTopicMappings(int(float32(bench.topicCount)*(1.0-bench.ratio)), "strictMapping", false)
regexTopicMappings := genNTopicMappings(int(float32(bench.topicCount)*bench.ratio), "regexMapping", true)

Expand Down

0 comments on commit 233cfd9

Please sign in to comment.