Moved integration tests and reconfigured CI (#347)
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
parent
4a53a1d3d6
commit
f85e701efd
|
|
@ -48,7 +48,11 @@ jobs:
|
||||||
- run:
|
- run:
|
||||||
name: Run unit tests
|
name: Run unit tests
|
||||||
command: |
|
command: |
|
||||||
TEST_AMQP_URL=amqp://localhost/test ./hack/presubmit-test.sh | tee ${TEST_RESULTS}/go-test.out
|
./hack/unit-test.sh | tee ${TEST_RESULTS}/go-unit-test.out
|
||||||
|
- run:
|
||||||
|
name: Run integrations tests
|
||||||
|
command: |
|
||||||
|
TEST_AMQP_URL=amqp://localhost/test ./hack/integration-test.sh | tee ${TEST_RESULTS}/go-integration-test.out
|
||||||
|
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: gomod-cache-{{ checksum "go.sum" }}
|
key: gomod-cache-{{ checksum "go.sum" }}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Run integration tests not in parallel
|
||||||
|
go test -v -parallel 1 ./test/... -coverprofile ${TEST_RESULTS:-.}/integration_test_cover.out -timeout 60s
|
||||||
|
|
||||||
|
# Remove test only deps.
|
||||||
|
go mod tidy
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# Test everything in pkg and cmd, except amqp
|
|
||||||
go test -v ./pkg/... ./cmd/... -coverprofile cover.out -timeout 15s
|
|
||||||
|
|
||||||
# AMQP & Kafka cannot run tests in parallel
|
|
||||||
go test -v -parallel 1 -tags amqp ./pkg/bindings/amqp -coverprofile amqp_bindings_cover.out -timeout 15s
|
|
||||||
go test -v -parallel 1 -tags amqp ./pkg/cloudevents/transport/amqp -coverprofile amqp_transport_cover.out -timeout 15s
|
|
||||||
go test -v -parallel 1 -tags kafka ./pkg/bindings/kafka_sarama -coverprofile kafka_bindings_cover.out -timeout 15s
|
|
||||||
|
|
||||||
# Test everything in test with a slightly longer timeout
|
|
||||||
go test ./test/... -timeout 60s
|
|
||||||
|
|
||||||
# Remove test only deps.
|
|
||||||
go mod tidy
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Test everything in pkg and cmd, except amqp
|
||||||
|
go test -v ./pkg/... ./cmd/... -coverprofile ${TEST_RESULTS:-.}/unit_test_cover.out -timeout 15s
|
||||||
|
|
||||||
|
# Remove test only deps.
|
||||||
|
go mod tidy
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
// +build kafka
|
|
||||||
|
|
||||||
package kafka_sarama_test
|
package kafka_sarama_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Shopify/sarama"
|
||||||
|
|
||||||
|
cloudevents "github.com/cloudevents/sdk-go"
|
||||||
"github.com/cloudevents/sdk-go/pkg/binding"
|
"github.com/cloudevents/sdk-go/pkg/binding"
|
||||||
|
"github.com/cloudevents/sdk-go/pkg/binding/test"
|
||||||
"github.com/cloudevents/sdk-go/pkg/bindings/kafka_sarama"
|
"github.com/cloudevents/sdk-go/pkg/bindings/kafka_sarama"
|
||||||
"github.com/cloudevents/sdk-go/pkg/event"
|
"github.com/cloudevents/sdk-go/pkg/event"
|
||||||
)
|
)
|
||||||
|
|
@ -16,54 +18,112 @@ var M binding.Message
|
||||||
var Event event.Event
|
var Event event.Event
|
||||||
var Err error
|
var Err error
|
||||||
|
|
||||||
|
var (
|
||||||
|
e = test.FullEvent()
|
||||||
|
structuredConsumerMessageWithoutKey = &sarama.ConsumerMessage{
|
||||||
|
Value: test.MustJSON(e),
|
||||||
|
Headers: []*sarama.RecordHeader{{
|
||||||
|
Key: []byte("content-type"),
|
||||||
|
Value: []byte(cloudevents.ApplicationCloudEventsJSON),
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
structuredConsumerMessageWithKey = &sarama.ConsumerMessage{
|
||||||
|
Key: []byte("aaa"),
|
||||||
|
Value: test.MustJSON(e),
|
||||||
|
Headers: []*sarama.RecordHeader{{
|
||||||
|
Key: []byte("content-type"),
|
||||||
|
Value: []byte(cloudevents.ApplicationCloudEventsJSON),
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
binaryConsumerMessageWithoutKey = &sarama.ConsumerMessage{
|
||||||
|
Value: []byte("hello world!"),
|
||||||
|
Headers: mustToSaramaConsumerHeaders(map[string]string{
|
||||||
|
"ce_type": e.Type(),
|
||||||
|
"ce_source": e.Source(),
|
||||||
|
"ce_id": e.ID(),
|
||||||
|
"ce_time": test.Timestamp.String(),
|
||||||
|
"ce_specversion": "1.0",
|
||||||
|
"ce_dataschema": test.Schema.String(),
|
||||||
|
"ce_datacontenttype": "text/json",
|
||||||
|
"ce_subject": "topic",
|
||||||
|
"ce_exta": "someext",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
binaryConsumerMessageWithKey = &sarama.ConsumerMessage{
|
||||||
|
Key: []byte("akey"),
|
||||||
|
Value: []byte("hello world!"),
|
||||||
|
Headers: mustToSaramaConsumerHeaders(map[string]string{
|
||||||
|
"ce_type": e.Type(),
|
||||||
|
"ce_source": e.Source(),
|
||||||
|
"ce_id": e.ID(),
|
||||||
|
"ce_time": test.Timestamp.String(),
|
||||||
|
"ce_specversion": "1.0",
|
||||||
|
"ce_dataschema": test.Schema.String(),
|
||||||
|
"ce_datacontenttype": "text/json",
|
||||||
|
"ce_subject": "topic",
|
||||||
|
"ce_exta": "someext",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func BenchmarkNewStructuredMessageWithoutKey(b *testing.B) {
|
func BenchmarkNewStructuredMessageWithoutKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.StructuredConsumerMessageWithoutKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(structuredConsumerMessageWithoutKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewStructuredMessageWithKey(b *testing.B) {
|
func BenchmarkNewStructuredMessageWithKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.StructuredConsumerMessageWithKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(structuredConsumerMessageWithKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewBinaryMessageWithoutKey(b *testing.B) {
|
func BenchmarkNewBinaryMessageWithoutKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.BinaryConsumerMessageWithoutKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(binaryConsumerMessageWithoutKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewBinaryMessageWithKey(b *testing.B) {
|
func BenchmarkNewBinaryMessageWithKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.BinaryConsumerMessageWithKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(binaryConsumerMessageWithKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewStructuredMessageWithoutKeyToEvent(b *testing.B) {
|
func BenchmarkNewStructuredMessageWithoutKeyToEvent(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.StructuredConsumerMessageWithoutKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(structuredConsumerMessageWithoutKey)
|
||||||
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewStructuredMessageWithKeyToEvent(b *testing.B) {
|
func BenchmarkNewStructuredMessageWithKeyToEvent(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.StructuredConsumerMessageWithKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(structuredConsumerMessageWithKey)
|
||||||
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewBinaryMessageWithoutKeyToEvent(b *testing.B) {
|
func BenchmarkNewBinaryMessageWithoutKeyToEvent(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.BinaryConsumerMessageWithoutKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(binaryConsumerMessageWithoutKey)
|
||||||
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkNewBinaryMessageWithKeyToEvent(b *testing.B) {
|
func BenchmarkNewBinaryMessageWithKeyToEvent(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
M, Err = kafka_sarama.NewMessageFromConsumerMessage(kafka_sarama.BinaryConsumerMessageWithKey)
|
M, Err = kafka_sarama.NewMessageFromConsumerMessage(binaryConsumerMessageWithKey)
|
||||||
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
Event, _, Err = binding.ToEvent(context.TODO(), M, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mustToSaramaConsumerHeaders(m map[string]string) []*sarama.RecordHeader {
|
||||||
|
res := make([]*sarama.RecordHeader, len(m))
|
||||||
|
i := 0
|
||||||
|
for k, v := range m {
|
||||||
|
res[i] = &sarama.RecordHeader{Key: []byte(k), Value: []byte(v)}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
// +build kafka
|
|
||||||
|
|
||||||
package kafka_sarama_test
|
package kafka_sarama_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -45,27 +43,27 @@ func init() {
|
||||||
func BenchmarkEncodeStructuredMessageSkipKey(b *testing.B) {
|
func BenchmarkEncodeStructuredMessageSkipKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ProducerMessage = &sarama.ProducerMessage{}
|
ProducerMessage = &sarama.ProducerMessage{}
|
||||||
Err = kafka_sarama.EncodeKafkaProducerMessage(ctxSkipKey, structuredMessageWithoutKey, ProducerMessage, binding.TransformerFactories{})
|
Err = kafka_sarama.EncodeKafkaProducerMessage(ctxSkipKey, structuredMessageWithoutKey, ProducerMessage, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEncodeStructuredMessage(b *testing.B) {
|
func BenchmarkEncodeStructuredMessage(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ProducerMessage = &sarama.ProducerMessage{}
|
ProducerMessage = &sarama.ProducerMessage{}
|
||||||
Err = kafka_sarama.EncodeKafkaProducerMessage(ctx, structuredMessageWithKey, ProducerMessage, binding.TransformerFactories{})
|
Err = kafka_sarama.EncodeKafkaProducerMessage(ctx, structuredMessageWithKey, ProducerMessage, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEncodeBinaryMessageSkipKey(b *testing.B) {
|
func BenchmarkEncodeBinaryMessageSkipKey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ProducerMessage = &sarama.ProducerMessage{}
|
ProducerMessage = &sarama.ProducerMessage{}
|
||||||
Err = kafka_sarama.EncodeKafkaProducerMessage(ctxSkipKey, binaryMessageWithoutKey, ProducerMessage, binding.TransformerFactories{})
|
Err = kafka_sarama.EncodeKafkaProducerMessage(ctxSkipKey, binaryMessageWithoutKey, ProducerMessage, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEncodeBinaryMessage(b *testing.B) {
|
func BenchmarkEncodeBinaryMessage(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ProducerMessage = &sarama.ProducerMessage{}
|
ProducerMessage = &sarama.ProducerMessage{}
|
||||||
Err = kafka_sarama.EncodeKafkaProducerMessage(ctx, binaryMessageWithKey, ProducerMessage, binding.TransformerFactories{})
|
Err = kafka_sarama.EncodeKafkaProducerMessage(ctx, binaryMessageWithKey, ProducerMessage, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
// +build kafka
|
|
||||||
|
|
||||||
package kafka_sarama
|
package kafka_sarama
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
// +build amqp
|
package amqp_binding
|
||||||
|
|
||||||
package amqp
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -15,6 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/cloudevents/sdk-go/pkg/binding"
|
"github.com/cloudevents/sdk-go/pkg/binding"
|
||||||
"github.com/cloudevents/sdk-go/pkg/binding/test"
|
"github.com/cloudevents/sdk-go/pkg/binding/test"
|
||||||
|
amqp2 "github.com/cloudevents/sdk-go/pkg/bindings/amqp"
|
||||||
"github.com/cloudevents/sdk-go/pkg/event"
|
"github.com/cloudevents/sdk-go/pkg/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -99,13 +98,13 @@ func testClient(t testing.TB) (client *amqp.Client, session *amqp.Session, addr
|
||||||
return client, session, addr
|
return client, session, addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSenderReceiver(t testing.TB, senderOptions ...SenderOptionFunc) (io.Closer, binding.Sender, binding.Receiver) {
|
func testSenderReceiver(t testing.TB, senderOptions ...amqp2.SenderOptionFunc) (io.Closer, binding.Sender, binding.Receiver) {
|
||||||
c, ss, a := testClient(t)
|
c, ss, a := testClient(t)
|
||||||
r, err := ss.NewReceiver(amqp.LinkSourceAddress(a))
|
r, err := ss.NewReceiver(amqp.LinkSourceAddress(a))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
s, err := ss.NewSender(amqp.LinkTargetAddress(a))
|
s, err := ss.NewSender(amqp.LinkTargetAddress(a))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return c, NewSender(s, senderOptions...), &receiver{r}
|
return c, amqp2.NewSender(s, senderOptions...), amqp2.NewReceiver(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSendReceive(b *testing.B) {
|
func BenchmarkSendReceive(b *testing.B) {
|
||||||
|
|
@ -11,10 +11,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/cloudevents/sdk-go"
|
"github.com/cloudevents/sdk-go"
|
||||||
"github.com/cloudevents/sdk-go/pkg/cloudevents/transport"
|
"github.com/cloudevents/sdk-go/pkg/cloudevents/transport"
|
||||||
cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
|
cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Conversion Test:
|
// Conversion Test:
|
||||||
|
|
@ -2,10 +2,11 @@ package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/google/uuid"
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
cloudevents "github.com/cloudevents/sdk-go"
|
cloudevents "github.com/cloudevents/sdk-go"
|
||||||
cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
|
cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
|
||||||
)
|
)
|
||||||
|
|
@ -6,9 +6,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
cloudevents "github.com/cloudevents/sdk-go"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
|
|
||||||
|
cloudevents "github.com/cloudevents/sdk-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package http_test
|
package http_binding_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
// +build kafka
|
package kafka_sarama_binding
|
||||||
|
|
||||||
package kafka_sarama
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -13,9 +11,9 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
cloudevents "github.com/cloudevents/sdk-go"
|
|
||||||
"github.com/cloudevents/sdk-go/pkg/binding"
|
"github.com/cloudevents/sdk-go/pkg/binding"
|
||||||
"github.com/cloudevents/sdk-go/pkg/binding/test"
|
"github.com/cloudevents/sdk-go/pkg/binding/test"
|
||||||
|
"github.com/cloudevents/sdk-go/pkg/bindings/kafka_sarama"
|
||||||
"github.com/cloudevents/sdk-go/pkg/event"
|
"github.com/cloudevents/sdk-go/pkg/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -23,54 +21,6 @@ const (
|
||||||
TEST_GROUP_ID = "test_group_id"
|
TEST_GROUP_ID = "test_group_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
e = test.FullEvent()
|
|
||||||
StructuredConsumerMessageWithoutKey = &sarama.ConsumerMessage{
|
|
||||||
Value: test.MustJSON(e),
|
|
||||||
Headers: []*sarama.RecordHeader{{
|
|
||||||
Key: []byte(contentTypeHeader),
|
|
||||||
Value: []byte(cloudevents.ApplicationCloudEventsJSON),
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
StructuredConsumerMessageWithKey = &sarama.ConsumerMessage{
|
|
||||||
Key: []byte("aaa"),
|
|
||||||
Value: test.MustJSON(e),
|
|
||||||
Headers: []*sarama.RecordHeader{{
|
|
||||||
Key: []byte(contentTypeHeader),
|
|
||||||
Value: []byte(cloudevents.ApplicationCloudEventsJSON),
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
BinaryConsumerMessageWithoutKey = &sarama.ConsumerMessage{
|
|
||||||
Value: []byte("hello world!"),
|
|
||||||
Headers: mustToSaramaConsumerHeaders(map[string]string{
|
|
||||||
"ce_type": e.Type(),
|
|
||||||
"ce_source": e.Source(),
|
|
||||||
"ce_id": e.ID(),
|
|
||||||
"ce_time": test.Timestamp.String(),
|
|
||||||
"ce_specversion": "1.0",
|
|
||||||
"ce_dataschema": test.Schema.String(),
|
|
||||||
"ce_datacontenttype": "text/json",
|
|
||||||
"ce_subject": "topic",
|
|
||||||
"ce_exta": "someext",
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
BinaryConsumerMessageWithKey = &sarama.ConsumerMessage{
|
|
||||||
Key: []byte("akey"),
|
|
||||||
Value: []byte("hello world!"),
|
|
||||||
Headers: mustToSaramaConsumerHeaders(map[string]string{
|
|
||||||
"ce_type": e.Type(),
|
|
||||||
"ce_source": e.Source(),
|
|
||||||
"ce_id": e.ID(),
|
|
||||||
"ce_time": test.Timestamp.String(),
|
|
||||||
"ce_specversion": "1.0",
|
|
||||||
"ce_dataschema": test.Schema.String(),
|
|
||||||
"ce_datacontenttype": "text/json",
|
|
||||||
"ce_subject": "topic",
|
|
||||||
"ce_exta": "someext",
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSendStructuredMessageToStructuredWithKey(t *testing.T) {
|
func TestSendStructuredMessageToStructuredWithKey(t *testing.T) {
|
||||||
close, s, r := testSenderReceiver(t)
|
close, s, r := testSenderReceiver(t)
|
||||||
defer close()
|
defer close()
|
||||||
|
|
@ -153,12 +103,12 @@ func testClient(t testing.TB) sarama.Client {
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSenderReceiver(t testing.TB, options ...SenderOptionFunc) (func(), binding.Sender, binding.Receiver) {
|
func testSenderReceiver(t testing.TB, options ...kafka_sarama.SenderOptionFunc) (func(), binding.Sender, binding.Receiver) {
|
||||||
client := testClient(t)
|
client := testClient(t)
|
||||||
|
|
||||||
topicName := "test-ce-client-" + uuid.New().String()
|
topicName := "test-ce-client-" + uuid.New().String()
|
||||||
r := NewReceiver(client, TEST_GROUP_ID, topicName)
|
r := kafka_sarama.NewReceiver(client, TEST_GROUP_ID, topicName)
|
||||||
s, err := NewSender(client, topicName, options...)
|
s, err := kafka_sarama.NewSender(client, topicName, options...)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return func() {
|
return func() {
|
||||||
|
|
@ -176,13 +126,3 @@ func BenchmarkSendReceive(b *testing.B) {
|
||||||
defer c() // Cleanup
|
defer c() // Cleanup
|
||||||
test.BenchmarkSendReceive(b, s, r)
|
test.BenchmarkSendReceive(b, s, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustToSaramaConsumerHeaders(m map[string]string) []*sarama.RecordHeader {
|
|
||||||
res := make([]*sarama.RecordHeader, len(m))
|
|
||||||
i := 0
|
|
||||||
for k, v := range m {
|
|
||||||
res[i] = &sarama.RecordHeader{Key: []byte(k), Value: []byte(v)}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue