1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-04 22:17:59 +08:00
Manuel Imperiale a7c3cfcf1c
MF-1154 - Move UUID provider to project root (#1172)
* MF-1154 - Move UUID provider to project root

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Use naming uuidProvider/up instead of identityProvider/idp

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Mutualize UUID mocks

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Move uuid into pkg directory

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-06-03 18:49:44 +02:00

55 lines
1.3 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package grpc_test
import (
"fmt"
"net"
"os"
"testing"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/pkg/uuid"
"github.com/mainflux/mainflux/things"
grpcapi "github.com/mainflux/mainflux/things/api/auth/grpc"
"github.com/mainflux/mainflux/things/mocks"
"github.com/opentracing/opentracing-go/mocktracer"
"google.golang.org/grpc"
)
const (
port = 8080
token = "token"
wrong = "wrong"
email = "john.doe@email.com"
)
var svc things.Service
func TestMain(m *testing.M) {
startServer()
code := m.Run()
os.Exit(code)
}
func startServer() {
svc = newService(map[string]string{token: email})
listener, _ := net.Listen("tcp", fmt.Sprintf(":%d", port))
server := grpc.NewServer()
mainflux.RegisterThingsServiceServer(server, grpcapi.NewServer(mocktracer.New(), svc))
go server.Serve(listener)
}
func newService(tokens map[string]string) things.Service {
auth := mocks.NewAuthService(tokens)
conns := make(chan mocks.Connection)
thingsRepo := mocks.NewThingRepository(conns)
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
return things.New(auth, thingsRepo, channelsRepo, chanCache, thingCache, uuidProvider)
}