-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from batchcorp/blinktag/handle_binary_kafka_h…
…eaders Handle kafka headers containing binary values
- Loading branch information
Showing
5 changed files
with
128 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,70 @@ | ||
package kafka | ||
|
||
//import ( | ||
// . "github.com/onsi/ginkgo" | ||
// . "github.com/onsi/gomega" | ||
// | ||
// "github.com/batchcorp/plumber/options" | ||
//) | ||
// | ||
//var _ = Describe("Kafka", func() { | ||
// Context("getAuthenticationMechanism", func() { | ||
// It("Returns nil when no username/password is specified", func() { | ||
// opts := &options.Options{Kafka: &options.KafkaOptions{ | ||
// Username: "", | ||
// Password: "", | ||
// }} | ||
// | ||
// m, err := getAuthenticationMechanism(opts) | ||
// | ||
// Expect(err).ToNot(HaveOccurred()) | ||
// Expect(m).To(BeNil()) | ||
// }) | ||
// | ||
// It("Returns SCRAM mechanism", func() { | ||
// opts := &options.Options{Kafka: &options.KafkaOptions{ | ||
// Username: "testing", | ||
// Password: "hunter2", | ||
// AuthenticationType: "scram", | ||
// }} | ||
// | ||
// m, err := getAuthenticationMechanism(opts) | ||
// | ||
// Expect(err).ToNot(HaveOccurred()) | ||
// Expect(m).ToNot(BeNil()) | ||
// Expect(m.Name()).To(Equal("SCRAM-SHA-512")) | ||
// }) | ||
// | ||
// It("Returns Plain mechanism", func() { | ||
// opts := &options.Options{Kafka: &options.KafkaOptions{ | ||
// Username: "testing", | ||
// Password: "hunter2", | ||
// AuthenticationType: "plain", | ||
// }} | ||
// | ||
// m, err := getAuthenticationMechanism(opts) | ||
// | ||
// Expect(err).ToNot(HaveOccurred()) | ||
// Expect(m).ToNot(BeNil()) | ||
// Expect(m.Name()).To(Equal("PLAIN")) | ||
// }) | ||
// }) | ||
//}) | ||
import ( | ||
"encoding/binary" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
skafka "github.com/segmentio/kafka-go" | ||
|
||
"github.com/batchcorp/plumber-schemas/build/go/protos/args" | ||
) | ||
|
||
var _ = Describe("Kafka", func() { | ||
Context("getAuthenticationMechanism", func() { | ||
It("Returns nil when no username/password is specified", func() { | ||
opts := &args.KafkaConn{ | ||
SaslUsername: "", | ||
SaslPassword: "", | ||
} | ||
|
||
m, err := getAuthenticationMechanism(opts) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(m).To(BeNil()) | ||
}) | ||
|
||
It("Returns SCRAM mechanism", func() { | ||
opts := &args.KafkaConn{ | ||
SaslUsername: "testing", | ||
SaslPassword: "hunter2", | ||
SaslType: args.SASLType_SCRAM, | ||
} | ||
|
||
m, err := getAuthenticationMechanism(opts) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(m).ToNot(BeNil()) | ||
Expect(m.Name()).To(Equal("SCRAM-SHA-512")) | ||
}) | ||
|
||
It("Returns Plain mechanism", func() { | ||
opts := &args.KafkaConn{ | ||
SaslUsername: "testing", | ||
SaslPassword: "hunter2", | ||
SaslType: args.SASLType_PLAIN, | ||
} | ||
|
||
m, err := getAuthenticationMechanism(opts) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(m).ToNot(BeNil()) | ||
Expect(m.Name()).To(Equal("PLAIN")) | ||
}) | ||
}) | ||
|
||
Context("convertKafkaHeaders", func() { | ||
It("handles values which cannot be converted to utf8 string", func() { | ||
var ts [8]byte | ||
binary.LittleEndian.PutUint64(ts[:], uint64(1640101168)) | ||
|
||
headers := []skafka.Header{ | ||
{Key: "key", Value: ts[:]}, | ||
} | ||
|
||
converted := convertKafkaHeadersToProto(headers) | ||
Expect(len(converted)).To(Equal(1)) | ||
Expect(converted[0].Value).To(Equal("MPXBYQAAAAA=")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package relay | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
skafka "github.com/segmentio/kafka-go" | ||
) | ||
|
||
var _ = Describe("Relay", func() { | ||
Context("convertKafkaHeaders", func() { | ||
It("handles values which cannot be converted to utf8 string", func() { | ||
var ts [8]byte | ||
binary.LittleEndian.PutUint64(ts[:], uint64(1640101168)) | ||
|
||
headers := []skafka.Header{ | ||
{Key: "key", Value: ts[:]}, | ||
} | ||
|
||
converted := convertKafkaHeaders(headers) | ||
Expect(len(converted)).To(Equal(1)) | ||
Expect(converted[0].Value).To(Equal("MPXBYQAAAAA=")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package relay_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestRelay(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Relay Suite") | ||
} |