2020-02-08 21:35:47 +00:00
|
|
|
package testtools
|
|
|
|
|
|
|
|
import (
|
|
|
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
2021-10-12 21:52:13 +00:00
|
|
|
"go.uber.org/zap"
|
2022-01-03 17:07:56 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-02-08 21:35:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeMessage struct {
|
|
|
|
qos byte
|
|
|
|
topic string
|
|
|
|
payload []byte
|
|
|
|
acked bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Duplicate() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Qos() byte {
|
|
|
|
return f.qos
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Retained() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Topic() string {
|
|
|
|
return f.topic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) MessageID() uint16 {
|
|
|
|
return 1234
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Payload() []byte {
|
|
|
|
return f.payload
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeMessage) Ack() {
|
|
|
|
f.acked = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFakeMessage(topic string, payload []byte) mqtt.Message {
|
|
|
|
return &fakeMessage{
|
|
|
|
qos: 0,
|
|
|
|
topic: topic,
|
|
|
|
payload: payload,
|
|
|
|
acked: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 21:52:13 +00:00
|
|
|
func NewFakeMessageFromProtobuf(topic string, msg proto.Message) mqtt.Message {
|
2020-02-08 21:35:47 +00:00
|
|
|
payload, err := proto.Marshal(msg)
|
2021-10-12 21:52:13 +00:00
|
|
|
if err != nil {
|
|
|
|
zap.S().Errorf("unable to marshal protobuf message %T: %v", msg, err)
|
2020-02-08 21:35:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return NewFakeMessage(topic, payload)
|
|
|
|
}
|