Skip to content

Commit

Permalink
Use idProvider instead of uuidProvider
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
  • Loading branch information
manuio committed Jan 14, 2021
1 parent b5f0a8e commit fc5061e
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 36 deletions.
4 changes: 2 additions & 2 deletions auth/api/grpc/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ var svc auth.Service
func newService() auth.Service {
repo := mocks.NewKeyRepository()
groupRepo := mocks.NewGroupRepository()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()
t := jwt.New(secret)

return auth.New(repo, groupRepo, uuidProvider, t)
return auth.New(repo, groupRepo, idProvider, t)
}

func startGRPCServer(svc auth.Service, port int) {
Expand Down
4 changes: 2 additions & 2 deletions auth/api/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (tr testRequest) make() (*http.Response, error) {
func newService() auth.Service {
repo := mocks.NewKeyRepository()
groupRepo := mocks.NewGroupRepository()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()
t := jwt.New(secret)
return auth.New(repo, groupRepo, uuidProvider, t)
return auth.New(repo, groupRepo, idProvider, t)
}

func newServer(svc auth.Service) *httptest.Server {
Expand Down
4 changes: 2 additions & 2 deletions auth/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const (
func newService() auth.Service {
repo := mocks.NewKeyRepository()
groupRepo := mocks.NewGroupRepository()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()
t := jwt.New(secret)
return auth.New(repo, groupRepo, uuidProvider, t)
return auth.New(repo, groupRepo, idProvider, t)
}

func TestIssue(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ func newService(db *sqlx.DB, tracer opentracing.Tracer, secret string, logger lo
groupsRepo := postgres.NewGroupRepo(database)
groupsRepo = tracing.GroupRepositoryMiddleware(tracer, groupsRepo)

uuidProvider := uuid.New()
idProvider := uuid.New()
t := jwt.New(secret)
svc := auth.New(keysRepo, groupsRepo, uuidProvider, t)

svc := auth.New(keysRepo, groupsRepo, idProvider, t)
svc = api.LoggingMiddleware(svc, logger)
svc = api.MetricsMiddleware(
svc,
Expand Down
4 changes: 2 additions & 2 deletions cmd/things/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ func newService(auth mainflux.AuthServiceClient, dbTracer opentracing.Tracer, ca

thingCache := rediscache.NewThingCache(cacheClient)
thingCache = tracing.ThingCacheMiddleware(cacheTracer, thingCache)
uuidProvider := uuid.New()
idProvider := uuid.New()

svc := things.New(auth, thingsRepo, channelsRepo, groupsRepo, chanCache, thingCache, uuidProvider)
svc := things.New(auth, thingsRepo, channelsRepo, groupsRepo, chanCache, thingCache, idProvider)
svc = rediscache.NewEventStoreMiddleware(svc, esClient)
svc = api.LoggingMiddleware(svc, logger)
svc = api.MetricsMiddleware(
Expand Down
4 changes: 2 additions & 2 deletions cmd/twins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ func newService(ps messaging.PubSub, chanID string, users mainflux.AuthServiceCl
stateRepo := twmongodb.NewStateRepository(db)
stateRepo = tracing.StateRepositoryMiddleware(dbTracer, stateRepo)

uuidProvider := uuid.New()
idProvider := uuid.New()
twinCache := rediscache.NewTwinCache(cacheClient)
twinCache = tracing.TwinCacheMiddleware(cacheTracer, twinCache)

svc := twins.New(ps, users, twinRepo, twinCache, stateRepo, uuidProvider, chanID, logger)
svc := twins.New(ps, users, twinRepo, twinCache, stateRepo, idProvider, chanID, logger)
svc = api.LoggingMiddleware(svc, logger)
svc = api.MetricsMiddleware(
svc,
Expand Down
4 changes: 2 additions & 2 deletions cmd/users/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ func newService(db *sqlx.DB, tracer opentracing.Tracer, auth mainflux.AuthServic
logger.Error(fmt.Sprintf("Failed to configure e-mailing util: %s", err.Error()))
}

uuidProvider := uuid.New()
idProvider := uuid.New()

svc := users.New(userRepo, groupRepo, hasher, auth, emailer, uuidProvider)
svc := users.New(userRepo, groupRepo, hasher, auth, emailer, idProvider)
svc = api.LoggingMiddleware(svc, logger)
svc = api.MetricsMiddleware(
svc,
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/go/things_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func newThingsService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}

func newThingsServer(svc things.Service) *httptest.Server {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/go/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func newUserService() users.Service {
hasher := mocks.NewHasher()
auth := mocks.NewAuthService(map[string]string{"user@example.com": "user@example.com"})
emailer := mocks.NewEmailer()
uuidProvider := uuid.New()
idProvider := uuid.New()

return users.New(usersRepo, groupsRepo, hasher, auth, emailer, uuidProvider)
return users.New(usersRepo, groupsRepo, hasher, auth, emailer, idProvider)
}

func newUserServer(svc users.Service) *httptest.Server {
Expand Down
4 changes: 2 additions & 2 deletions things/api/auth/grpc/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}
4 changes: 2 additions & 2 deletions things/api/auth/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func newService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}

func newServer(svc things.Service) *httptest.Server {
Expand Down
4 changes: 2 additions & 2 deletions things/api/things/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func newService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}

func newServer(svc things.Service) *httptest.Server {
Expand Down
4 changes: 2 additions & 2 deletions things/redis/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func newService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}

func TestCreateThings(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions things/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func newService(tokens map[string]string) things.Service {
channelsRepo := mocks.NewChannelRepository(thingsRepo, conns)
chanCache := mocks.NewChannelCache()
thingCache := mocks.NewThingCache()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()

return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, uuidProvider)
return things.New(auth, thingsRepo, channelsRepo, nil, chanCache, thingCache, idProvider)
}

func TestCreateThings(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions twins/mocks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func NewService(tokens map[string]string) twins.Service {
twinsRepo := NewTwinRepository()
twinCache := NewTwinCache()
statesRepo := NewStateRepository()
uuidProvider := uuid.NewMock()
idProvider := uuid.NewMock()
subs := map[string]string{"chanID": "chanID"}
broker := NewBroker(subs)
return twins.New(broker, auth, twinsRepo, twinCache, statesRepo, uuidProvider, "chanID", nil)

return twins.New(broker, auth, twinsRepo, twinCache, statesRepo, idProvider, "chanID", nil)
}

// CreateDefinition creates twin definition
Expand Down
4 changes: 2 additions & 2 deletions users/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func newService() users.Service {
hasher := bcrypt.New()
auth := mocks.NewAuthService(map[string]string{user.Email: user.Email})
email := mocks.NewEmailer()
uuidProvider := uuid.New()
idProvider := uuid.New()

return users.New(usersRepo, groupRepo, hasher, auth, email, uuidProvider)
return users.New(usersRepo, groupRepo, hasher, auth, email, idProvider)
}

func newServer(svc users.Service) *httptest.Server {
Expand Down
6 changes: 3 additions & 3 deletions users/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
host = "example.com"
groupName = "Mainflux"

uuidProvider = uuid.New()
idProvider = uuid.New()
)

func newService() users.Service {
Expand All @@ -36,7 +36,7 @@ func newService() users.Service {
auth := mocks.NewAuthService(map[string]string{user.Email: user.Email})
e := mocks.NewEmailer()

return users.New(userRepo, groupRepo, hasher, auth, e, uuidProvider)
return users.New(userRepo, groupRepo, hasher, auth, e, idProvider)
}

func TestRegister(t *testing.T) {
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestCreateGroup(t *testing.T) {
token, err := svc.Login(context.Background(), user)
assert.Nil(t, err, fmt.Sprintf("authenticating user expected to succeed: %s", err))

id, err := uuidProvider.ID()
id, err := idProvider.ID()
assert.Nil(t, err, fmt.Sprintf("generating uuid expected to succeed: %s", err))

group := users.Group{
Expand Down
2 changes: 1 addition & 1 deletion uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package mainflux

// UUIDProvider specifies an API for generating unique identifiers.
// IDProvider specifies an API for generating unique identifiers.
type IDProvider interface {
// ID generates the unique identifier.
ID() (string, error)
Expand Down

0 comments on commit fc5061e

Please sign in to comment.