-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge_test.go
41 lines (31 loc) · 954 Bytes
/
bridge_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package bridge
import (
"testing"
"time"
mqtt "github.com/eclipse/paho.mqtt.golang"
"go.uber.org/zap"
echo "github.com/golain-io/mqtt-bridge/example"
)
func setupTestBridge(t *testing.T) (*MQTTBridge, echo.EchoServiceServer) {
// Create MQTT client
opts := mqtt.NewClientOptions().
AddBroker("tcp://localhost:1883").
SetClientID("test-bridge")
mqttClient := mqtt.NewClient(opts)
token := mqttClient.Connect()
if token.Wait() && token.Error() != nil {
t.Fatalf("Failed to connect to MQTT broker: %v", token.Error())
}
// Create logger
logger, _ := zap.NewDevelopment()
// Create bridge
bridge := NewMQTTBridge(mqttClient, logger, 30*time.Second)
// Create and register echo service
echoServer := echo.NewEchoServer()
bridge.RegisterService(&echo.EchoService_ServiceDesc, echoServer)
return bridge, echoServer
}
func TestEchoUnary(t *testing.T) {
bridge, _ := setupTestBridge(t)
defer bridge.mqttClient.Disconnect(0)
}