mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-1087 - Remove WebSocket adapter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm all ws directory Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Revert authorization.js Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Remove /ws endpoint from ssl/authorization.js Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm gorilla from vendor Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Revert gorilla to vendor Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
48 lines
998 B
Go
48 lines
998 B
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package mocks
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux/broker"
|
|
"github.com/mainflux/mainflux/errors"
|
|
"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 errors.New("failed to publish")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (mb mockBroker) Subscribe(subject string, f func(*nats.Msg)) (*nats.Subscription, error) {
|
|
if _, ok := mb.subscriptions[subject]; !ok {
|
|
return nil, errors.New("failed to subscribe")
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func (mb mockBroker) QueueSubscribe(chanID, subtopic string, f func(*nats.Msg)) (*nats.Subscription, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (mb mockBroker) Close() {
|
|
}
|