mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
We expect a few messages in each partition.
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//go:build !release
|
|
|
|
package kafka
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/twmb/franz-go/pkg/kfake"
|
|
|
|
"akvorado/common/daemon"
|
|
"akvorado/common/helpers"
|
|
"akvorado/common/kafka"
|
|
"akvorado/common/reporter"
|
|
)
|
|
|
|
// DefaultMockKafkaNumPartitions is the default number of partitions for the mock Kafka.
|
|
const DefaultMockKafkaNumPartitions = 8
|
|
|
|
// NewMock creates a new Kafka component with a mocked Kafka. It will
|
|
// panic if it cannot be started.
|
|
func NewMock(t *testing.T, r *reporter.Reporter, configuration Configuration) (*Component, *kfake.Cluster) {
|
|
t.Helper()
|
|
// Use a fake Kafka cluster for testing
|
|
cluster, err := kfake.NewCluster(
|
|
kfake.NumBrokers(1),
|
|
kfake.AllowAutoTopicCreation(),
|
|
kfake.DefaultNumPartitions(DefaultMockKafkaNumPartitions),
|
|
kfake.WithLogger(kafka.NewLogger(r)),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("NewCluster() error: %v", err)
|
|
}
|
|
t.Cleanup(func() {
|
|
cluster.Close()
|
|
})
|
|
configuration.Brokers = cluster.ListenAddrs()
|
|
|
|
c, err := New(r, configuration, Dependencies{
|
|
Daemon: daemon.NewMock(t),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("New() error:\n%+v", err)
|
|
}
|
|
helpers.StartStop(t, c)
|
|
return c, cluster
|
|
}
|
|
|
|
// Flush force flushing the currently buffered records.
|
|
func (c *Component) Flush(t *testing.T) {
|
|
if err := c.kafkaClient.Flush(t.Context()); err != nil {
|
|
t.Fatalf("Flush() error:\n%+v", err)
|
|
}
|
|
}
|