1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-01 13:48:56 +08:00
Ivan Milošević effade00aa MF-325 - Add SPDX license and copyright headers (#362)
* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Change mainflux version from 0.4.0 to 0.5.0

Signed-off-by: Ivan Milošević <iva@blokovi.com>
2018-08-26 13:15:48 +02:00

53 lines
1.1 KiB
Go

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package grpc_test
import (
"fmt"
"net"
"os"
"testing"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/things"
grpcapi "github.com/mainflux/mainflux/things/api/grpc"
"github.com/mainflux/mainflux/things/mocks"
"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(svc))
go server.Serve(listener)
}
func newService(tokens map[string]string) things.Service {
users := mocks.NewUsersService(tokens)
thingsRepo := mocks.NewThingRepository()
channelsRepo := mocks.NewChannelRepository(thingsRepo)
idp := mocks.NewIdentityProvider()
return things.New(users, thingsRepo, channelsRepo, idp)
}