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

* Add open tracing dependencies Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add open tracing to users service Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add open tracing to the things service Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add open tracing to the http adapter Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add open tracing to the ws adapter Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add open tracing to the CoAP adapter Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update LoRa adapter in accordance with changes Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update SDK tests in accordance with changes Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update bootstrap service in accordance with changes Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update reader services with accordance with changes Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update .env and docker-compose file Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Add jaeger and timeout env vars Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Fix broken test for can access by id endpoint Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com> * Update deps with proto empty package Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
//
|
|
// Copyright (c) 2019
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package grpc_test
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
"github.com/mainflux/mainflux/users"
|
|
grpcapi "github.com/mainflux/mainflux/users/api/grpc"
|
|
"github.com/mainflux/mainflux/users/mocks"
|
|
"github.com/opentracing/opentracing-go/mocktracer"
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
const port = 8081
|
|
|
|
var (
|
|
user = users.User{
|
|
Email: "john.doe@email.com",
|
|
Password: "pass",
|
|
}
|
|
svc users.Service
|
|
)
|
|
|
|
func newService() users.Service {
|
|
repo := mocks.NewUserRepository()
|
|
hasher := mocks.NewHasher()
|
|
idp := mocks.NewIdentityProvider()
|
|
|
|
return users.New(repo, hasher, idp)
|
|
}
|
|
|
|
func startGRPCServer(svc users.Service, port int) {
|
|
listener, _ := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
|
server := grpc.NewServer()
|
|
mainflux.RegisterUsersServiceServer(server, grpcapi.NewServer(mocktracer.New(), svc))
|
|
go server.Serve(listener)
|
|
}
|
|
|
|
func TestIdentify(t *testing.T) {
|
|
svc.Register(context.Background(), user)
|
|
|
|
usersAddr := fmt.Sprintf("localhost:%d", port)
|
|
conn, _ := grpc.Dial(usersAddr, grpc.WithInsecure())
|
|
client := grpcapi.NewClient(mocktracer.New(), conn, time.Second)
|
|
|
|
cases := map[string]struct {
|
|
token string
|
|
id string
|
|
err error
|
|
}{
|
|
"identify user with valid token": {user.Email, user.Email, nil},
|
|
"identify user that doesn't exist": {"", "", status.Error(codes.InvalidArgument, "received invalid token request")},
|
|
}
|
|
|
|
for desc, tc := range cases {
|
|
id, err := client.Identify(context.Background(), &mainflux.Token{Value: tc.token})
|
|
assert.Equal(t, tc.id, id.GetValue(), fmt.Sprintf("%s: expected %s got %s", desc, tc.id, id.GetValue()))
|
|
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s", desc, tc.err, err))
|
|
}
|
|
}
|