1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00
Mainflux.mainflux/ws/mocks/messages.go
Aleksandar Novaković aea7db14b7 NOISSUE - Raise code coverage in ws adapter (#242)
* Fix failed subscription handling in ws adapter

Fix unsubscribing bug in ws adapter.

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add subscription fail and publish fail test cases

Update mock implementation to receive publish error in order to
support these test cases.

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update mainflux version to 0.2.3

Update project version and load tests version to 0.2.3.

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update version endpoint response format

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
2018-04-24 13:56:13 +02:00

35 lines
769 B
Go

package mocks
import (
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/ws"
)
var _ ws.Service = (*mockService)(nil)
type mockService struct {
subscriptions map[string]ws.Channel
pubError error
}
// NewService returns mock message publisher.
func NewService(subs map[string]ws.Channel, pubError error) ws.Service {
return mockService{subs, pubError}
}
func (svc mockService) Publish(msg mainflux.RawMessage) error {
if len(msg.Payload) == 0 {
return svc.pubError
}
svc.subscriptions[msg.Channel].Messages <- msg
return nil
}
func (svc mockService) Subscribe(chanID string, channel ws.Channel) error {
if _, ok := svc.subscriptions[chanID]; !ok {
return ws.ErrFailedSubscription
}
svc.subscriptions[chanID] = channel
return nil
}