mirror of
https://github.com/dpup/meshstream.git
synced 2026-03-28 17:42:37 +01:00
Update tests to inject loggers
- Add logger injection in client_test.go - Add logger injection in broker_test.go - Add test logger with appropriate test namespace - Fix all tests to work with updated constructor signatures
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/dpup/prefab/logging"
|
||||
|
||||
"meshstream/decoder"
|
||||
)
|
||||
|
||||
@@ -14,7 +16,8 @@ func TestBrokerSubscribeUnsubscribe(t *testing.T) {
|
||||
sourceChan := make(chan *Packet, 10)
|
||||
|
||||
// Create a broker with the source channel
|
||||
broker := NewBroker(sourceChan)
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
broker := NewBroker(sourceChan, testLogger)
|
||||
defer broker.Close()
|
||||
|
||||
// Subscribe to the broker
|
||||
@@ -99,7 +102,8 @@ func TestBrokerMultipleSubscribers(t *testing.T) {
|
||||
sourceChan := make(chan *Packet, 10)
|
||||
|
||||
// Create a broker with the source channel
|
||||
broker := NewBroker(sourceChan)
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
broker := NewBroker(sourceChan, testLogger)
|
||||
defer broker.Close()
|
||||
|
||||
// Create multiple subscribers
|
||||
@@ -144,7 +148,8 @@ func TestBrokerSlowSubscriber(t *testing.T) {
|
||||
sourceChan := make(chan *Packet, 10)
|
||||
|
||||
// Create a broker with the source channel
|
||||
broker := NewBroker(sourceChan)
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
broker := NewBroker(sourceChan, testLogger)
|
||||
defer broker.Close()
|
||||
|
||||
// Create a slow subscriber with buffer size 1
|
||||
@@ -215,7 +220,8 @@ func TestBrokerCloseWithSubscribers(t *testing.T) {
|
||||
sourceChan := make(chan *Packet, 10)
|
||||
|
||||
// Create a broker with the source channel
|
||||
broker := NewBroker(sourceChan)
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
broker := NewBroker(sourceChan, testLogger)
|
||||
|
||||
// Subscribe to the broker
|
||||
subscriber := broker.Subscribe(5)
|
||||
|
||||
@@ -3,6 +3,8 @@ package mqtt
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/dpup/prefab/logging"
|
||||
)
|
||||
|
||||
// TestClientConfig verifies that the client can be created with a config
|
||||
@@ -15,7 +17,8 @@ func TestClientConfig(t *testing.T) {
|
||||
Topic: "test/topic",
|
||||
}
|
||||
|
||||
client := NewClient(config)
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
client := NewClient(config, testLogger)
|
||||
if client == nil {
|
||||
t.Fatal("Expected client to be created, got nil")
|
||||
}
|
||||
@@ -46,7 +49,8 @@ func TestClientConfig(t *testing.T) {
|
||||
// This test is a mock test and doesn't actually connect to MQTT
|
||||
// It just verifies that the messages channel works as expected
|
||||
func TestMessagesChannel(t *testing.T) {
|
||||
client := NewClient(Config{})
|
||||
testLogger := logging.NewDevLogger().Named("test")
|
||||
client := NewClient(Config{}, testLogger)
|
||||
ch := client.Messages()
|
||||
|
||||
// Verify we get the channel
|
||||
|
||||
Reference in New Issue
Block a user