Mainflux.mainflux/pkg/uuid/mock.go

36 lines
699 B
Go
Raw Normal View History

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package uuid
import (
"fmt"
"sync"
"github.com/mainflux/mainflux"
)
// Prefix represents the prefix used to generate UUID mocks
const Prefix = "123e4567-e89b-12d3-a456-"
NOISSUE - Fix dates not being init properly on save, change path construction, replace UUID with ULID for group ID (#1300) * fix path, group saving with parent Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change path, enable name change Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert changes for port Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * replace UUID with ULID Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert user groups Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid provider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * enable group name change Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * use null string for parent id Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove migrations, disable group delete if group not empty Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert docker compose Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid provider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove dash character replacment Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid lib Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * rename UUIDProvider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * rename package alias Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused error Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2020-12-18 00:08:28 +08:00
var _ mainflux.IDProvider = (*uuidProviderMock)(nil)
type uuidProviderMock struct {
mu sync.Mutex
counter int
}
func (up *uuidProviderMock) ID() (string, error) {
up.mu.Lock()
defer up.mu.Unlock()
up.counter++
return fmt.Sprintf("%s%012d", Prefix, up.counter), nil
}
// NewMock creates "mirror" uuid provider, i.e. generated
// token will hold value provided by the caller.
NOISSUE - Fix dates not being init properly on save, change path construction, replace UUID with ULID for group ID (#1300) * fix path, group saving with parent Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * change path, enable name change Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert changes for port Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * replace UUID with ULID Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix migrations Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert user groups Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid provider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * enable group name change Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * use null string for parent id Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove migrations, disable group delete if group not empty Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * revert docker compose Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid provider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove dash character replacment Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * add ulid lib Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * rename UUIDProvider Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * rename package alias Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * remove unused error Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2020-12-18 00:08:28 +08:00
func NewMock() mainflux.IDProvider {
return &uuidProviderMock{}
}