Mainflux.mainflux/twins/mocks/messages.go

48 lines
980 B
Go
Raw Normal View History

NOISSUE - Create broker package for NATS (#1080) * NOISSUEE - Create broker package for NATS Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Create funcs to return NATS connection Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * mv os.exit to main Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix Reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix tests and typos Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix CI Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Unify Publisher and Subscriber interfaces Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename Nats interface Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Mv message.pb.go, messsage.proto and topics.go to broker directory Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix go.mod Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use mainflux broker for writers and twins services Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix go.mod Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix twins tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix make proto Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix message.proto Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix golangcibot Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * regenerate message.pb.go Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix comment Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix comment Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix make proto Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add NATS errors Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-04-02 03:22:13 +08:00
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package mocks
import (
"context"
"github.com/mainflux/mainflux/broker"
"github.com/mainflux/mainflux/ws"
"github.com/nats-io/nats.go"
)
var _ broker.Nats = (*mockBroker)(nil)
type mockBroker struct {
subscriptions map[string]string
}
// New returns mock message publisher.
func New(sub map[string]string) broker.Nats {
return &mockBroker{
subscriptions: sub,
}
}
func (mb mockBroker) Publish(_ context.Context, _ string, msg broker.Message) error {
if len(msg.Payload) == 0 {
return ws.ErrFailedMessagePublish
}
return nil
}
func (mb mockBroker) Subscribe(subject string, f func(*nats.Msg)) (*nats.Subscription, error) {
if _, ok := mb.subscriptions[subject]; !ok {
return nil, ws.ErrFailedSubscription
}
return nil, nil
}
func (mb mockBroker) QueueSubscribe(chanID, subtopic string, f func(*nats.Msg)) (*nats.Subscription, error) {
return nil, nil
}
func (mb mockBroker) Close() {
}