Skip to content

Commit

Permalink
viper.GetStringSlice() doesn't work like i expected it to
Browse files Browse the repository at this point in the history
  • Loading branch information
dehort committed Sep 23, 2024
1 parent 50c52ab commit 2b3036b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/common/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func LoadSchemas(cfg *viper.Viper, schemaNames []string) (schemas []*jsonschema.
}

func IsOrgIdBlocklisted(cfg *viper.Viper, orgId string) bool {
blocklistedOrgIds := cfg.GetStringSlice("blocklist.org.ids")
blocklistedOrgIds := strings.Split(cfg.GetString("blocklist.org.ids"), ",")
if len(blocklistedOrgIds) > 0 {
for _, blockedOrgId := range blocklistedOrgIds {
if blockedOrgId == orgId {
Expand Down
32 changes: 28 additions & 4 deletions internal/validator/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ package validator
import (
"bytes"
"encoding/base64"
"encoding/json"
"io/ioutil"
"playbook-dispatcher/internal/common/constants"
kafkaUtils "playbook-dispatcher/internal/common/kafka"
messageModel "playbook-dispatcher/internal/common/model/message"
"playbook-dispatcher/internal/common/utils/test"

k "github.com/confluentinc/confluent-kafka-go/kafka"

"github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
Expand Down Expand Up @@ -61,12 +66,14 @@ var _ = Describe("Handler", func() {
cfg.Set("blocklist.org.ids", "1337")

req := &messageModel.IngressValidationRequest{
OrgID: "1337",
Size: 1024,
OrgID: "1337",
Size: 1024,
RequestID: "1234-56789",
}

err := instance.validateRequest(req)
Expect(err).To(HaveOccurred())
kafkaMessage := newKafkaMessage(req, playbookPayloadHeaderValue)

instance.onMessage(test.TestContext(), kafkaMessage)
})
})

Expand Down Expand Up @@ -199,3 +206,20 @@ fdqPl7IwpOzJmfqrZ1duqTJ62NbTeDDPjOvQ6F70PsJi4KXiLSqngthpIkJLtF3l

// TODO: test parsing (timestamps, etc.)
})

func newKafkaMessage(value interface{}, requestType string) *k.Message {
marshalled, err := json.Marshal(value)
Expect(err).ToNot(HaveOccurred())

topic := "platform.upload.announce"

return &k.Message{
Value: marshalled,
Headers: kafkaUtils.Headers(constants.HeaderRequestId, "test", constants.HeaderRequestType, requestType),
TopicPartition: k.TopicPartition{
Topic: &topic,
Partition: 0,
Offset: k.Offset(0),
},
}
}

0 comments on commit 2b3036b

Please sign in to comment.