Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dependent integration test in example #784

Merged
merged 9 commits into from
Jul 4, 2024
34 changes: 33 additions & 1 deletion examples/using-subscriber/main_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
package main

import (
"context"
"strings"
"testing"
"time"

"gofr.dev/pkg/gofr/datasource/pubsub/kafka"
"gofr.dev/pkg/gofr/logging"
"gofr.dev/pkg/gofr/testutil"
)

type mock struct {
}

func (m *mock) IncrementCounter(ctx context.Context, name string, labels ...string) {
}

func initializeTest(t *testing.T) {
c := kafka.New(kafka.Config{
Broker: "localhost:9092",
OffSet: 1,
BatchSize: kafka.DefaultBatchSize,
BatchBytes: kafka.DefaultBatchBytes,
BatchTimeout: kafka.DefaultBatchTimeout,
Partition: 1,
}, logging.NewMockLogger(logging.INFO), &mock{})

err := c.Publish(context.Background(), "order-logs", []byte(`{"data":{"orderId":"123","status":"pending"}}`))
if err != nil {
t.Errorf("Error while publishing: %v", err)
}

err = c.Publish(context.Background(), "products", []byte(`{"data":{"productId":"123","price":"599"}}`))
if err != nil {
t.Errorf("Error while publishing: %v", err)
}
}

func TestExampleSubscriber(t *testing.T) {
initializeTest(t)

log := testutil.StdoutOutputForFunc(func() {
const host = "http://localhost:8200"
go main()
time.Sleep(time.Minute * 2)
time.Sleep(time.Second * 40)
})

testCases := []struct {
Expand Down
Loading