Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package kafka
import (
"context"
"testing"
"fiskerinc.com/modules/testhelper"
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
)
var producerConfig = &kafka.ConfigMap{
"socket.timeout.ms": 10,
"message.timeout.ms": 10,
}
func TestProducer(t *testing.T) {
p, err := kafka.NewProducer(producerConfig)
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", nil, err)
}
producer := &Producer{producer: p}
err = producer.Produce("gotopic", "key", "test", nil)
if err == nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", "Local: Message timed out", err)
}
}
func TestProducerError(t *testing.T) {
p, err := kafka.NewProducer(producerConfig)
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", nil, err)
}
producer := &Producer{producer: p}
err = producer.Produce("", "key", "test", nil)
if err == nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", "Local: Invalid argument of configuration", err)
}
}
func TestProduceBinary(t *testing.T) {
t.Skip()
ctx := context.Background()
producer, err := NewProducer(ctx)
if err != nil {
t.Error(err)
return
}
err = producer.ProduceBinary("topic", "key", []byte("This is a test"), nil)
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", "Local: Invalid argument of configuration", err)
}
err = producer.ProduceBinary("topic", "key", []byte("This is a test"), map[string][]byte{
"key1": []byte("val1"),
"key2": []byte("val2"),
})
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestProducer", "Local: Invalid argument of configuration", err)
}
}