1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Dušan Borovčanin 516c02bebe
MF-1378 - Update dependencies (#1379)
* Update dependencies

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix compose files and configs

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Upgrade image versions

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update Postgres version

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update test dependencies

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix fkey error handling

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
2021-05-20 20:53:56 +02:00

68 lines
1.1 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package mocks
import (
"context"
"errors"
"sync"
"github.com/mainflux/mainflux/lora"
)
type routeMapMock struct {
mu sync.Mutex
routes map[string]string
}
// NewRouteMap returns mock route-map instance.
func NewRouteMap() lora.RouteMapRepository {
return &routeMapMock{
routes: make(map[string]string),
}
}
func (trm *routeMapMock) Save(_ context.Context, mfxID, extID string) error {
trm.mu.Lock()
defer trm.mu.Unlock()
trm.routes[extID] = mfxID
trm.routes[mfxID] = extID
return nil
}
func (trm *routeMapMock) Get(_ context.Context, extID string) (string, error) {
trm.mu.Lock()
defer trm.mu.Unlock()
id, ok := trm.routes[extID]
if !ok {
return "", errors.New("route-map not found")
}
return id, nil
}
func (trm *routeMapMock) Remove(_ context.Context, extID string) error {
trm.mu.Lock()
defer trm.mu.Unlock()
var mfxID string
for i, val := range trm.routes {
if val == extID {
mfxID = val
delete(trm.routes, i)
}
}
for i, val := range trm.routes {
if val == mfxID {
delete(trm.routes, i)
return nil
}
}
return nil
}