1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-24 13:48:49 +08:00
Mainflux.mainflux/things/service_test.go

1057 lines
25 KiB
Go
Raw Normal View History

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package things_test
2018-05-10 23:53:25 +02:00
import (
2019-07-18 15:01:09 +02:00
"context"
2018-05-10 23:53:25 +02:00
"fmt"
"testing"
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
"time"
2018-05-10 23:53:25 +02:00
"github.com/mainflux/mainflux/pkg/errors"
"github.com/mainflux/mainflux/pkg/uuid"
"github.com/mainflux/mainflux/things"
"github.com/mainflux/mainflux/things/mocks"
2018-05-10 23:53:25 +02:00
"github.com/stretchr/testify/assert"
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
"github.com/stretchr/testify/require"
2018-05-10 23:53:25 +02:00
)
const (
MF-475 - Replace increment ID with UUID (#490) * 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>
2018-12-05 13:09:25 +01:00
wrongID = ""
wrongValue = "wrong-value"
email = "user@example.com"
token = "token"
2018-05-10 23:53:25 +02:00
)
var (
thing = things.Thing{Name: "test"}
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
channel = things.Channel{Name: "test"}
2018-05-10 23:53:25 +02:00
)
func newService(tokens map[string]string) things.Service {
MF-932 - User API keys (#941) * Add inital Auth implementation Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Extract IssuedAt on transport layer Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add token type Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix Auth service URL in Things service Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Add User Keys revocation check Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove unused tracing methods Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix Key retrival and parsing Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove unused code Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Increase test coverage Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix compose files Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix typos Simplify tests. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix typos and remove useless comments Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Rename Auth to Authn Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Rename database.go to tracin.go A new name (`tracing.go`) describes better the purpose of the file. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Increase test coverage Fix typo. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Increase test coverage Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove token from Users service Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix identify login keys Rename token parsing method. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Extract tokenizer to interface Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove pointer time Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Use pointer for expiration time in response Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Use uppercase N Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove unnecessary email check Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Cleanup unused code and env vars Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Rename tokenizer field Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Use slices and named fields in test cases Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update AuthN keys naming Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove package-lock.json changes Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove Secret from issuing request Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
2019-12-16 16:22:09 +01:00
auth := mocks.NewAuthService(tokens)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
conns := make(chan mocks.Connection)
thingsRepo := mocks.NewThingRepository(conns)
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
idProvider := uuid.NewMock()
2018-05-10 23:53:25 +02:00
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
2018-05-10 23:53:25 +02:00
}
func TestCreateThings(t *testing.T) {
svc := newService(map[string]string{token: email})
cases := []struct {
desc string
things []things.Thing
token string
err error
}{
{
desc: "create new things",
things: []things.Thing{{Name: "a"}, {Name: "b"}, {Name: "c"}, {Name: "d"}},
token: token,
err: nil,
},
{
desc: "create thing with wrong credentials",
things: []things.Thing{{Name: "e"}},
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
}
for _, tc := range cases {
_, err := svc.CreateThings(context.Background(), tc.token, tc.things...)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
}
}
func TestUpdateThing(t *testing.T) {
2018-05-10 23:53:25 +02:00
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
other := things.Thing{ID: wrongID, Key: "x"}
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
thing things.Thing
token string
err error
2018-05-10 23:53:25 +02:00
}{
{
desc: "update existing thing",
thing: th,
token: token,
err: nil,
},
{
desc: "update thing with wrong credentials",
thing: th,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
{
desc: "update non-existing thing",
thing: other,
token: token,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.UpdateThing(context.Background(), tc.token, tc.thing)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
}
}
func TestUpdateKey(t *testing.T) {
key := "new-key"
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
cases := []struct {
desc string
token string
id string
key string
err error
}{
{
desc: "update key of an existing thing",
token: token,
id: th.ID,
key: key,
err: nil,
},
{
desc: "update key with invalid credentials",
token: wrongValue,
id: th.ID,
key: key,
err: things.ErrUnauthorizedAccess,
},
{
desc: "update key of non-existing thing",
token: token,
id: wrongID,
key: wrongValue,
err: things.ErrNotFound,
},
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.UpdateKey(context.Background(), tc.token, tc.id, tc.key)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestViewThing(t *testing.T) {
2018-05-10 23:53:25 +02:00
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
2018-05-10 23:53:25 +02:00
cases := map[string]struct {
id string
token string
err error
2018-05-10 23:53:25 +02:00
}{
"view existing thing": {
id: th.ID,
token: token,
err: nil,
},
"view thing with wrong credentials": {
id: th.ID,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
"view non-existing thing": {
id: wrongID,
token: token,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for desc, tc := range cases {
2019-07-18 15:01:09 +02:00
_, err := svc.ViewThing(context.Background(), tc.token, tc.id)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestListThings(t *testing.T) {
2018-05-10 23:53:25 +02:00
svc := newService(map[string]string{token: email})
NOISSUE - Search by metadata (#849) * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add space Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata test case Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add docs and update swagger Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove commented out section Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change to test Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove debug printf Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small fix for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix tests Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * and => and/or Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add line Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix mixed func params Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata will be added to channels later Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix return type Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add migration Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove var Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * respecting the order of migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-09-17 13:46:24 +00:00
m := make(map[string]interface{})
m["serial"] = "123456"
thing.Metadata = m
n := uint64(10)
for i := uint64(0); i < n; i++ {
_, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
2018-05-10 23:53:25 +02:00
}
2018-05-10 23:53:25 +02:00
cases := map[string]struct {
token string
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
pageMetadata things.PageMetadata
size uint64
err error
2018-05-10 23:53:25 +02:00
}{
"list all things": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
},
size: n,
err: nil,
},
"list half": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n / 2,
Limit: n,
},
size: n / 2,
err: nil,
},
"list last thing": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n - 1,
Limit: n,
},
size: 1,
err: nil,
},
"list empty set": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n + 1,
Limit: n,
},
size: 0,
err: nil,
},
"list with zero limit": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 1,
Limit: 0,
},
size: 0,
err: nil,
},
"list with wrong credentials": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: wrongValue,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: 0,
},
size: 0,
err: things.ErrUnauthorizedAccess,
},
NOISSUE - Search by metadata (#849) * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add space Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata test case Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add docs and update swagger Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove commented out section Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change to test Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove debug printf Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small fix for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix tests Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * and => and/or Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add line Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix mixed func params Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata will be added to channels later Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix return type Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add migration Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove var Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * respecting the order of migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-09-17 13:46:24 +00:00
"list with metadata": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
Metadata: m,
},
size: n,
err: nil,
NOISSUE - Search by metadata (#849) * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata search Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add space Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata test case Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add docs and update swagger Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add test for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove commented out section Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change to test Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove debug printf Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small fix for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix tests Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * and => and/or Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add line Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix mixed func params Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * metadata will be added to channels later Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix return type Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix typings Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add migration Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove var Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * respecting the order of migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-09-17 13:46:24 +00:00
},
2018-05-10 23:53:25 +02:00
}
for desc, tc := range cases {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
page, err := svc.ListThings(context.Background(), tc.token, tc.pageMetadata)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
size := uint64(len(page.Things))
assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size))
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}
}
func TestListThingsByChannel(t *testing.T) {
svc := newService(map[string]string{token: email})
chs, err := svc.CreateChannels(context.Background(), token, channel)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
ch := chs[0]
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
n := uint64(10)
thsDisconNum := uint64(1)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
for i := uint64(0); i < n; i++ {
ths, err := svc.CreateThings(context.Background(), token, thing)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
th := ths[0]
// Don't connect last Channel
if i == n-thsDisconNum {
break
}
err = svc.Connect(context.Background(), token, []string{ch.ID}, []string{th.ID})
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}
// Wait for things and channels to connect
time.Sleep(time.Second)
cases := map[string]struct {
token string
channel string
offset uint64
limit uint64
connected bool
size uint64
err error
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}{
"list all things by existing channel": {
token: token,
channel: ch.ID,
offset: 0,
limit: n,
connected: true,
size: n - thsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list half of things by existing channel": {
token: token,
channel: ch.ID,
offset: n / 2,
limit: n,
connected: true,
size: (n / 2) - thsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list last thing by existing channel": {
token: token,
channel: ch.ID,
offset: n - 1 - thsDisconNum,
limit: n,
connected: true,
size: 1,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list empty set of things by existing channel": {
token: token,
channel: ch.ID,
offset: n + 1,
limit: n,
connected: true,
size: 0,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list things by existing channel with zero limit": {
token: token,
channel: ch.ID,
offset: 1,
limit: 0,
connected: true,
size: 0,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list things by existing channel with wrong credentials": {
token: wrongValue,
channel: ch.ID,
offset: 0,
limit: 0,
connected: true,
size: 0,
err: things.ErrUnauthorizedAccess,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list things by non-existent channel with wrong credentials": {
token: token,
channel: "non-existent",
offset: 0,
limit: 10,
connected: true,
size: 0,
err: nil,
},
"list all non connected things by existing channel": {
token: token,
channel: ch.ID,
offset: 0,
limit: n,
connected: false,
size: thsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
}
for desc, tc := range cases {
page, err := svc.ListThingsByChannel(context.Background(), tc.token, tc.channel, tc.offset, tc.limit, tc.connected)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
size := uint64(len(page.Things))
2018-05-10 23:53:25 +02:00
assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size))
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestRemoveThing(t *testing.T) {
2018-05-10 23:53:25 +02:00
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
sth := ths[0]
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
id string
token string
err error
2018-05-10 23:53:25 +02:00
}{
{
desc: "remove thing with wrong credentials",
id: sth.ID,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
{
desc: "remove existing thing",
id: sth.ID,
token: token,
err: nil,
},
{
desc: "remove removed thing",
id: sth.ID,
token: token,
err: nil,
},
{
desc: "remove non-existing thing",
id: wrongID,
token: token,
err: nil,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.RemoveThing(context.Background(), tc.token, tc.id)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestCreateChannels(t *testing.T) {
svc := newService(map[string]string{token: email})
cases := []struct {
desc string
channels []things.Channel
token string
err error
}{
{
desc: "create new channels",
channels: []things.Channel{{Name: "a"}, {Name: "b"}, {Name: "c"}, {Name: "d"}},
token: token,
err: nil,
},
{
desc: "create channel with wrong credentials",
channels: []things.Channel{{Name: "e"}},
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
}
for _, cc := range cases {
_, err := svc.CreateChannels(context.Background(), cc.token, cc.channels...)
assert.True(t, errors.Contains(err, cc.err), fmt.Sprintf("%s: expected %s got %s\n", cc.desc, cc.err, err))
}
}
2018-05-10 23:53:25 +02:00
func TestUpdateChannel(t *testing.T) {
svc := newService(map[string]string{token: email})
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
other := things.Channel{ID: wrongID}
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
channel things.Channel
token string
2018-05-10 23:53:25 +02:00
err error
}{
{
desc: "update existing channel",
channel: ch,
token: token,
err: nil,
},
{
desc: "update channel with wrong credentials",
channel: ch,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
{
desc: "update non-existing channel",
channel: other,
token: token,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.UpdateChannel(context.Background(), tc.token, tc.channel)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestViewChannel(t *testing.T) {
svc := newService(map[string]string{token: email})
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
2018-05-10 23:53:25 +02:00
cases := map[string]struct {
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 14:12:52 +02:00
id string
token string
err error
metadata things.Metadata
2018-05-10 23:53:25 +02:00
}{
"view existing channel": {
id: ch.ID,
token: token,
err: nil,
},
"view channel with wrong credentials": {
id: ch.ID,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
"view non-existing channel": {
id: wrongID,
token: token,
err: things.ErrNotFound,
},
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 14:12:52 +02:00
"view channel with metadata": {
id: wrongID,
token: token,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for desc, tc := range cases {
2019-07-18 15:01:09 +02:00
_, err := svc.ViewChannel(context.Background(), tc.token, tc.id)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestListChannels(t *testing.T) {
svc := newService(map[string]string{token: email})
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 14:12:52 +02:00
meta := things.Metadata{}
meta["name"] = "test-channel"
channel.Metadata = meta
n := uint64(10)
for i := uint64(0); i < n; i++ {
svc.CreateChannels(context.Background(), token, channel)
2018-05-10 23:53:25 +02:00
}
cases := map[string]struct {
token string
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
pageMetadata things.PageMetadata
size uint64
err error
2018-05-10 23:53:25 +02:00
}{
"list all channels": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
},
size: n,
err: nil,
},
"list half": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n / 2,
Limit: n,
},
size: n / 2,
err: nil,
},
"list last channel": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n - 1,
Limit: n,
},
size: 1,
err: nil,
},
"list empty set": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: n + 1,
Limit: n,
},
size: 0,
err: nil,
},
"list with zero limit": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 1,
Limit: 0,
},
size: 0,
err: nil,
},
"list with wrong credentials": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: wrongValue,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: 0,
},
size: 0,
err: things.ErrUnauthorizedAccess,
},
"list with existing name": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
Name: "chanel_name",
},
size: n,
err: nil,
},
"list with non-existent name": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
Name: "wrong",
},
size: n,
err: nil,
},
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 14:12:52 +02:00
"list all channels with metadata": {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
token: token,
pageMetadata: things.PageMetadata{
Offset: 0,
Limit: n,
Metadata: meta,
},
size: n,
err: nil,
MF-859 - Channels metadata search (#867) * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add users metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * run.sh Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to users Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add default value for metadata Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * when metadata is not set dont save 'null' string Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change metadata type, add error handling Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add pause Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove extra char Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * retype from string to []byte Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add wait logic for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * few small fixes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix identityRes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add metadata to channels Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix waiting for gnatsd Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * changes to wait gnatsd logic Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * testing query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix query Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Update requests.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * Delete pwdrecovery.go Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix merge problem Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small change in comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused struct Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2019-10-01 14:12:52 +02:00
},
2018-05-10 23:53:25 +02:00
}
for desc, tc := range cases {
MF-1290 - Sort Things and Channels by name (#1293) * MF-1290 - Sort Things and Channels by name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add sort HTTP parameter and use PageMetadata to pass filters Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix channels conn list Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Replace sort naming by order Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add order in responses Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve order tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Improve getNameQuery func Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix commits Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add name-asc and name-desc Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add dir query parameter Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix test messages and openapi.yml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix openapi uuid format Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Check query parameters in endpoint layer Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add asc endpoint tests Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename pageMeta into pageMetadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-12-08 21:30:47 +01:00
page, err := svc.ListChannels(context.Background(), tc.token, tc.pageMetadata)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
size := uint64(len(page.Channels))
assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size))
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}
}
func TestListChannelsByThing(t *testing.T) {
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
th := ths[0]
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
n := uint64(10)
chsDisconNum := uint64(1)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
for i := uint64(0); i < n; i++ {
schs, err := svc.CreateChannels(context.Background(), token, channel)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
sch := schs[0]
// Don't connect last Channel
if i == n-chsDisconNum {
break
}
err = svc.Connect(context.Background(), token, []string{sch.ID}, []string{th.ID})
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}
// Wait for things and channels to connect.
time.Sleep(time.Second)
cases := map[string]struct {
token string
thing string
offset uint64
limit uint64
connected bool
size uint64
err error
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
}{
"list all channels by existing thing": {
token: token,
thing: th.ID,
offset: 0,
limit: n,
connected: true,
size: n - chsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list half of channels by existing thing": {
token: token,
thing: th.ID,
offset: n / 2,
limit: n,
connected: true,
size: (n / 2) - chsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list last channel by existing thing": {
token: token,
thing: th.ID,
offset: n - 1 - chsDisconNum,
limit: n,
connected: true,
size: 1,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list empty set of channels by existing thing": {
token: token,
thing: th.ID,
offset: n + 1,
limit: n,
connected: true,
size: 0,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list channels by existing thing with zero limit": {
token: token,
thing: th.ID,
offset: 1,
limit: 0,
connected: true,
size: 0,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list channels by existing thing with wrong credentials": {
token: wrongValue,
thing: th.ID,
offset: 0,
limit: 0,
connected: true,
size: 0,
err: things.ErrUnauthorizedAccess,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
"list channels by non-existent thing": {
token: token,
thing: "non-existent",
offset: 0,
limit: 10,
connected: true,
size: 0,
err: nil,
},
"list all non connected channels by existing thing": {
token: token,
thing: th.ID,
offset: 0,
limit: n,
connected: false,
size: chsDisconNum,
err: nil,
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
},
}
for desc, tc := range cases {
page, err := svc.ListChannelsByThing(context.Background(), tc.token, tc.thing, tc.offset, tc.limit, tc.connected)
MF-483 - Enable channels and devices corresponding lists in backend (#520) * Add list channels by thing id endpoint Add list channels by thing id endpoint to things service. Add pagination format and logic. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add fetch channels by thing endpoint Add fetch channels by thing endpoint with pagination. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update list endpoints to contain pagination Update list endpoints to contain pagination metadata. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add tests for two new endpoints Add tests for two new endpoints and update existing ones. Also, remove connected field from channel response. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix tests for SDK Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add SDK methods for new endpoints Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update swagger docs for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add error handling to http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Fix response body in http tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove unused responses from things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases to things postgres tests Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add test cases for event sourcing Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2019-01-08 11:53:24 +01:00
size := uint64(len(page.Channels))
2018-05-10 23:53:25 +02:00
assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected %d got %d\n", desc, tc.size, size))
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestRemoveChannel(t *testing.T) {
svc := newService(map[string]string{token: email})
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
id string
token string
err error
2018-05-10 23:53:25 +02:00
}{
{
desc: "remove channel with wrong credentials",
id: ch.ID,
token: wrongValue,
err: things.ErrUnauthorizedAccess,
},
{
desc: "remove existing channel",
id: ch.ID,
token: token,
err: nil,
},
{
desc: "remove removed channel",
id: ch.ID,
token: token,
err: nil,
},
{
desc: "remove non-existing channel",
id: ch.ID,
token: token,
err: nil,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.RemoveChannel(context.Background(), tc.token, tc.id)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestConnect(t *testing.T) {
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
token string
MF-475 - Replace increment ID with UUID (#490) * 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>
2018-12-05 13:09:25 +01:00
chanID string
thingID string
err error
2018-05-10 23:53:25 +02:00
}{
{
desc: "connect thing",
token: token,
chanID: ch.ID,
thingID: th.ID,
err: nil,
},
{
desc: "connect thing with wrong credentials",
token: wrongValue,
chanID: ch.ID,
thingID: th.ID,
err: things.ErrUnauthorizedAccess,
},
{
desc: "connect thing to non-existing channel",
token: token,
chanID: wrongID,
thingID: th.ID,
err: things.ErrNotFound,
},
{
desc: "connect non-existing thing to channel",
token: token,
chanID: ch.ID,
thingID: wrongID,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
err := svc.Connect(context.Background(), tc.token, []string{tc.chanID}, []string{tc.thingID})
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestDisconnect(t *testing.T) {
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
err = svc.Connect(context.Background(), token, []string{ch.ID}, []string{th.ID})
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
2018-05-10 23:53:25 +02:00
cases := []struct {
desc string
token string
MF-475 - Replace increment ID with UUID (#490) * 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>
2018-12-05 13:09:25 +01:00
chanID string
thingID string
err error
2018-05-10 23:53:25 +02:00
}{
{
desc: "disconnect connected thing",
token: token,
chanID: ch.ID,
thingID: th.ID,
err: nil,
},
{
desc: "disconnect disconnected thing",
token: token,
chanID: ch.ID,
thingID: th.ID,
err: things.ErrNotFound,
},
{
desc: "disconnect with wrong credentials",
token: wrongValue,
chanID: ch.ID,
thingID: th.ID,
err: things.ErrUnauthorizedAccess,
},
{
desc: "disconnect from non-existing channel",
token: token,
chanID: wrongID,
thingID: th.ID,
err: things.ErrNotFound,
},
{
desc: "disconnect non-existing thing",
token: token,
chanID: ch.ID,
thingID: wrongID,
err: things.ErrNotFound,
},
2018-05-10 23:53:25 +02:00
}
for _, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.Disconnect(context.Background(), tc.token, tc.chanID, tc.thingID)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestCanAccessByKey(t *testing.T) {
2018-05-10 23:53:25 +02:00
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
chs, err := svc.CreateChannels(context.Background(), token, channel, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
err = svc.Connect(context.Background(), token, []string{chs[0].ID}, []string{ths[0].ID})
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
2018-05-10 23:53:25 +02:00
cases := map[string]struct {
token string
MF-475 - Replace increment ID with UUID (#490) * 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>
2018-12-05 13:09:25 +01:00
channel string
2018-05-10 23:53:25 +02:00
err error
}{
"allowed access": {
token: ths[0].Key,
channel: chs[0].ID,
err: nil,
},
"non-existing thing": {
token: wrongValue,
channel: chs[0].ID,
err: things.ErrNotFound,
},
"non-existing chan": {
token: ths[0].Key,
channel: wrongValue,
err: things.ErrEntityConnected,
},
"non-connected channel": {
token: ths[0].Key,
channel: chs[1].ID,
err: things.ErrEntityConnected,
},
2018-05-10 23:53:25 +02:00
}
for desc, tc := range cases {
_, err := svc.CanAccessByKey(context.Background(), tc.channel, tc.token)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected '%s' got '%s'\n", desc, tc.err, err))
2018-05-10 23:53:25 +02:00
}
}
func TestCanAccessByID(t *testing.T) {
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ch := chs[0]
err = svc.Connect(context.Background(), token, []string{ch.ID}, []string{th.ID})
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
cases := map[string]struct {
thingID string
channel string
err error
}{
"allowed access": {
thingID: th.ID,
channel: ch.ID,
err: nil,
},
"access to non-existing thing": {
thingID: wrongValue,
channel: ch.ID,
err: things.ErrEntityConnected,
},
"access to non-existing channel": {
thingID: th.ID,
channel: wrongID,
err: things.ErrEntityConnected,
},
"access to not-connected thing": {
thingID: ths[1].ID,
channel: ch.ID,
err: things.ErrEntityConnected,
},
}
for desc, tc := range cases {
2019-07-18 15:01:09 +02:00
err := svc.CanAccessByID(context.Background(), tc.channel, tc.thingID)
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
}
}
func TestIdentify(t *testing.T) {
svc := newService(map[string]string{token: email})
ths, err := svc.CreateThings(context.Background(), token, thing)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
th := ths[0]
cases := map[string]struct {
token string
id string
err error
}{
"identify existing thing": {
token: th.Key,
id: th.ID,
err: nil,
},
"identify non-existing thing": {
token: wrongValue,
id: wrongID,
err: things.ErrNotFound,
},
}
for desc, tc := range cases {
2019-07-18 15:01:09 +02:00
id, err := svc.Identify(context.Background(), tc.token)
MF-475 - Replace increment ID with UUID (#490) * 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>
2018-12-05 13:09:25 +01:00
assert.Equal(t, tc.id, id, fmt.Sprintf("%s: expected %s got %s\n", desc, tc.id, id))
2020-03-30 15:22:18 +02:00
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
}
}