2019-10-07 22:14:47 +08:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 19:15:48 +08:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-08-06 23:06:55 +08:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-07-16 00:28:15 +08:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
|
|
|
2018-08-06 23:06:55 +08:00
|
|
|
"github.com/mainflux/mainflux"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2018-11-06 02:18:51 +08:00
|
|
|
var errUnauthorized = status.Error(codes.PermissionDenied, "missing or invalid credentials provided")
|
2018-08-06 23:06:55 +08:00
|
|
|
|
|
|
|
var _ mainflux.ThingsServiceClient = (*thingsServiceMock)(nil)
|
|
|
|
|
|
|
|
type thingsServiceMock struct{}
|
|
|
|
|
|
|
|
// NewThingsService returns mock implementation of things service
|
|
|
|
func NewThingsService() mainflux.ThingsServiceClient {
|
|
|
|
return thingsServiceMock{}
|
|
|
|
}
|
|
|
|
|
2019-10-22 05:24:45 +08:00
|
|
|
func (svc thingsServiceMock) CanAccessByKey(ctx context.Context, in *mainflux.AccessByKeyReq, opts ...grpc.CallOption) (*mainflux.ThingID, error) {
|
2018-08-06 23:06:55 +08:00
|
|
|
token := in.GetToken()
|
|
|
|
if token == "invalid" {
|
2018-11-06 02:18:51 +08:00
|
|
|
return nil, errUnauthorized
|
2018-08-06 23:06:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 20:09:25 +08:00
|
|
|
if token == "" {
|
2018-11-06 02:18:51 +08:00
|
|
|
return nil, errUnauthorized
|
2018-08-06 23:06:55 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 20:09:25 +08:00
|
|
|
return &mainflux.ThingID{Value: token}, nil
|
2018-08-06 23:06:55 +08:00
|
|
|
}
|
|
|
|
|
2019-07-16 00:28:15 +08:00
|
|
|
func (svc thingsServiceMock) CanAccessByID(context.Context, *mainflux.AccessByIDReq, ...grpc.CallOption) (*empty.Empty, error) {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2021-02-23 02:41:59 +08:00
|
|
|
func (svc thingsServiceMock) IsChannelOwner(context.Context, *mainflux.ChannelOwnerReq, ...grpc.CallOption) (*empty.Empty, error) {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2019-07-16 00:28:15 +08:00
|
|
|
func (svc thingsServiceMock) Identify(context.Context, *mainflux.Token, ...grpc.CallOption) (*mainflux.ThingID, error) {
|
|
|
|
panic("not implemented")
|
2018-08-06 23:06:55 +08:00
|
|
|
}
|