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

* Update increment ID to UUID in things service Update increment ID to UUID for things and channels in things service and proto files. Also, update ID type from uint to string. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in http adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in ws adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in CoAP adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in normalizer service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in writer services Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in reader services Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in SDK Update increment ID to UUID in SDK. Update id type to string. Update tests. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update increment ID to UUID in mqtt adapter Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unnecessary case from influxdb reader Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update tests in order to increase code coverage Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update lora adapter to use string ID instead of unsigned int Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
120 lines
2.3 KiB
Go
120 lines
2.3 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package redis_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
r "github.com/go-redis/redis"
|
|
"github.com/mainflux/mainflux/things/redis"
|
|
"github.com/mainflux/mainflux/things/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestThingSave(t *testing.T) {
|
|
thingCache := redis.NewThingCache(redisClient)
|
|
key := uuid.New().ID()
|
|
id := "123"
|
|
id2 := "124"
|
|
|
|
err := thingCache.Save(key, id2)
|
|
require.Nil(t, err, fmt.Sprintf("Save thing to cache: expected nil got %s", err))
|
|
|
|
cases := []struct {
|
|
desc string
|
|
ID string
|
|
key string
|
|
err error
|
|
}{
|
|
{
|
|
desc: "Save thing to cache",
|
|
ID: id,
|
|
key: key,
|
|
err: nil,
|
|
},
|
|
{
|
|
desc: "Save already cached thing to cache",
|
|
ID: id2,
|
|
key: key,
|
|
err: nil,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
err := thingCache.Save(tc.key, tc.ID)
|
|
assert.Nil(t, err, fmt.Sprintf("%s: expected %s got %s", tc.desc, tc.err, err))
|
|
|
|
}
|
|
}
|
|
|
|
func TestThingID(t *testing.T) {
|
|
thingCache := redis.NewThingCache(redisClient)
|
|
|
|
key := uuid.New().ID()
|
|
id := "123"
|
|
err := thingCache.Save(key, id)
|
|
require.Nil(t, err, fmt.Sprintf("Save thing to cache: expected nil got %s", err))
|
|
|
|
cases := map[string]struct {
|
|
ID string
|
|
key string
|
|
err error
|
|
}{
|
|
"Get ID by existing thing-key": {
|
|
ID: id,
|
|
key: key,
|
|
err: nil,
|
|
},
|
|
"Get ID by non-existing thing-key": {
|
|
ID: "",
|
|
key: wrongValue,
|
|
err: r.Nil,
|
|
},
|
|
}
|
|
|
|
for desc, tc := range cases {
|
|
cacheID, err := thingCache.ID(tc.key)
|
|
assert.Equal(t, tc.ID, cacheID, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.ID, cacheID))
|
|
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
|
|
}
|
|
}
|
|
|
|
func TestThingRemove(t *testing.T) {
|
|
thingCache := redis.NewThingCache(redisClient)
|
|
|
|
key := uuid.New().ID()
|
|
id := "123"
|
|
id2 := "321"
|
|
thingCache.Save(key, id)
|
|
|
|
cases := []struct {
|
|
desc string
|
|
ID string
|
|
err error
|
|
}{
|
|
{
|
|
desc: "Remove existing thing from cache",
|
|
ID: id,
|
|
err: nil,
|
|
},
|
|
{
|
|
desc: "Remove non-existing thing from cache",
|
|
ID: id2,
|
|
err: r.Nil,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
err := thingCache.Remove(tc.ID)
|
|
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
|
}
|
|
|
|
}
|