devicemanagement

package
v0.0.0-...-73aaac1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceAlreadyExist = fmt.Errorf("device already exists")
View Source
var ErrDeviceNotFound = fmt.Errorf("device not found")
View Source
var ErrDeviceProfileNotFound = fmt.Errorf("device profile not found")

Functions

Types

type DeviceManagement

type DeviceManagement interface {
	GetBySensorID(ctx context.Context, sensorID string, tenants []string) (types.Device, error)
	GetByDeviceID(ctx context.Context, deviceID string, tenants []string) (types.Device, error)
	GetOnlineDevices(ctx context.Context, offset, limit int) (types.Collection[types.Device], error)
	GetWithAlarmID(ctx context.Context, alarmID string, tenants []string) (types.Device, error)
	GetWithinBounds(ctx context.Context, bounds types.Bounds) (types.Collection[types.Device], error)

	Create(ctx context.Context, device types.Device) error
	Update(ctx context.Context, device types.Device) error
	Merge(ctx context.Context, deviceID string, fields map[string]any, tenants []string) error

	UpdateStatus(ctx context.Context, deviceID, tenant string, deviceStatus types.DeviceStatus) error
	UpdateState(ctx context.Context, deviceID, tenant string, deviceState types.DeviceState) error

	Seed(ctx context.Context, reader io.Reader, tenants []string) error

	GetLwm2mTypes(ctx context.Context, urn ...string) (types.Collection[types.Lwm2mType], error)
	GetDeviceProfiles(ctx context.Context, name ...string) (types.Collection[types.DeviceProfile], error)
	GetTenants(ctx context.Context) (types.Collection[string], error)

	Query(ctx context.Context, params map[string][]string, tenants []string) (types.Collection[types.Device], error)
}

type DeviceManagementConfig

type DeviceManagementConfig struct {
	DeviceProfiles []types.DeviceProfile `yaml:"deviceprofiles"`
	Types          []types.Lwm2mType     `yaml:"types"`
}

type DeviceManagementMock

type DeviceManagementMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(ctx context.Context, device models.Device) error

	// GetByDeviceIDFunc mocks the GetByDeviceID method.
	GetByDeviceIDFunc func(ctx context.Context, deviceID string, tenants []string) (models.Device, error)

	// GetBySensorIDFunc mocks the GetBySensorID method.
	GetBySensorIDFunc func(ctx context.Context, sensorID string, tenants []string) (models.Device, error)

	// GetDeviceProfilesFunc mocks the GetDeviceProfiles method.
	GetDeviceProfilesFunc func(ctx context.Context, name ...string) (models.Collection[models.DeviceProfile], error)

	// GetLwm2mTypesFunc mocks the GetLwm2mTypes method.
	GetLwm2mTypesFunc func(ctx context.Context, urn ...string) (models.Collection[models.Lwm2mType], error)

	// GetOnlineDevicesFunc mocks the GetOnlineDevices method.
	GetOnlineDevicesFunc func(ctx context.Context, offset int, limit int) (models.Collection[models.Device], error)

	// GetTenantsFunc mocks the GetTenants method.
	GetTenantsFunc func(ctx context.Context) (models.Collection[string], error)

	// GetWithAlarmIDFunc mocks the GetWithAlarmID method.
	GetWithAlarmIDFunc func(ctx context.Context, alarmID string, tenants []string) (models.Device, error)

	// GetWithinBoundsFunc mocks the GetWithinBounds method.
	GetWithinBoundsFunc func(ctx context.Context, bounds models.Bounds) (models.Collection[models.Device], error)

	// MergeFunc mocks the Merge method.
	MergeFunc func(ctx context.Context, deviceID string, fields map[string]any, tenants []string) error

	// QueryFunc mocks the Query method.
	QueryFunc func(ctx context.Context, params map[string][]string, tenants []string) (models.Collection[models.Device], error)

	// SeedFunc mocks the Seed method.
	SeedFunc func(ctx context.Context, reader io.Reader, tenants []string) error

	// UpdateFunc mocks the Update method.
	UpdateFunc func(ctx context.Context, device models.Device) error

	// UpdateStateFunc mocks the UpdateState method.
	UpdateStateFunc func(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error

	// UpdateStatusFunc mocks the UpdateStatus method.
	UpdateStatusFunc func(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error
	// contains filtered or unexported fields
}

DeviceManagementMock is a mock implementation of DeviceManagement.

func TestSomethingThatUsesDeviceManagement(t *testing.T) {

	// make and configure a mocked DeviceManagement
	mockedDeviceManagement := &DeviceManagementMock{
		CreateFunc: func(ctx context.Context, device models.Device) error {
			panic("mock out the Create method")
		},
		GetByDeviceIDFunc: func(ctx context.Context, deviceID string, tenants []string) (models.Device, error) {
			panic("mock out the GetByDeviceID method")
		},
		GetBySensorIDFunc: func(ctx context.Context, sensorID string, tenants []string) (models.Device, error) {
			panic("mock out the GetBySensorID method")
		},
		GetDeviceProfilesFunc: func(ctx context.Context, name ...string) (models.Collection[models.DeviceProfile], error) {
			panic("mock out the GetDeviceProfiles method")
		},
		GetLwm2mTypesFunc: func(ctx context.Context, urn ...string) (models.Collection[models.Lwm2mType], error) {
			panic("mock out the GetLwm2mTypes method")
		},
		GetOnlineDevicesFunc: func(ctx context.Context, offset int, limit int) (models.Collection[models.Device], error) {
			panic("mock out the GetOnlineDevices method")
		},
		GetTenantsFunc: func(ctx context.Context) (models.Collection[string], error) {
			panic("mock out the GetTenants method")
		},
		GetWithAlarmIDFunc: func(ctx context.Context, alarmID string, tenants []string) (models.Device, error) {
			panic("mock out the GetWithAlarmID method")
		},
		GetWithinBoundsFunc: func(ctx context.Context, bounds models.Bounds) (models.Collection[models.Device], error) {
			panic("mock out the GetWithinBounds method")
		},
		MergeFunc: func(ctx context.Context, deviceID string, fields map[string]any, tenants []string) error {
			panic("mock out the Merge method")
		},
		QueryFunc: func(ctx context.Context, params map[string][]string, tenants []string) (models.Collection[models.Device], error) {
			panic("mock out the Query method")
		},
		SeedFunc: func(ctx context.Context, reader io.Reader, tenants []string) error {
			panic("mock out the Seed method")
		},
		UpdateFunc: func(ctx context.Context, device models.Device) error {
			panic("mock out the Update method")
		},
		UpdateStateFunc: func(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error {
			panic("mock out the UpdateState method")
		},
		UpdateStatusFunc: func(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error {
			panic("mock out the UpdateStatus method")
		},
	}

	// use mockedDeviceManagement in code that requires DeviceManagement
	// and then make assertions.

}

func (*DeviceManagementMock) Create

func (mock *DeviceManagementMock) Create(ctx context.Context, device models.Device) error

Create calls CreateFunc.

func (*DeviceManagementMock) CreateCalls

func (mock *DeviceManagementMock) CreateCalls() []struct {
	Ctx    context.Context
	Device models.Device
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedDeviceManagement.CreateCalls())

func (*DeviceManagementMock) GetByDeviceID

func (mock *DeviceManagementMock) GetByDeviceID(ctx context.Context, deviceID string, tenants []string) (models.Device, error)

GetByDeviceID calls GetByDeviceIDFunc.

func (*DeviceManagementMock) GetByDeviceIDCalls

func (mock *DeviceManagementMock) GetByDeviceIDCalls() []struct {
	Ctx      context.Context
	DeviceID string
	Tenants  []string
}

GetByDeviceIDCalls gets all the calls that were made to GetByDeviceID. Check the length with:

len(mockedDeviceManagement.GetByDeviceIDCalls())

func (*DeviceManagementMock) GetBySensorID

func (mock *DeviceManagementMock) GetBySensorID(ctx context.Context, sensorID string, tenants []string) (models.Device, error)

GetBySensorID calls GetBySensorIDFunc.

func (*DeviceManagementMock) GetBySensorIDCalls

func (mock *DeviceManagementMock) GetBySensorIDCalls() []struct {
	Ctx      context.Context
	SensorID string
	Tenants  []string
}

GetBySensorIDCalls gets all the calls that were made to GetBySensorID. Check the length with:

len(mockedDeviceManagement.GetBySensorIDCalls())

func (*DeviceManagementMock) GetDeviceProfiles

func (mock *DeviceManagementMock) GetDeviceProfiles(ctx context.Context, name ...string) (models.Collection[models.DeviceProfile], error)

GetDeviceProfiles calls GetDeviceProfilesFunc.

func (*DeviceManagementMock) GetDeviceProfilesCalls

func (mock *DeviceManagementMock) GetDeviceProfilesCalls() []struct {
	Ctx  context.Context
	Name []string
}

GetDeviceProfilesCalls gets all the calls that were made to GetDeviceProfiles. Check the length with:

len(mockedDeviceManagement.GetDeviceProfilesCalls())

func (*DeviceManagementMock) GetLwm2mTypes

func (mock *DeviceManagementMock) GetLwm2mTypes(ctx context.Context, urn ...string) (models.Collection[models.Lwm2mType], error)

GetLwm2mTypes calls GetLwm2mTypesFunc.

func (*DeviceManagementMock) GetLwm2mTypesCalls

func (mock *DeviceManagementMock) GetLwm2mTypesCalls() []struct {
	Ctx context.Context
	Urn []string
}

GetLwm2mTypesCalls gets all the calls that were made to GetLwm2mTypes. Check the length with:

len(mockedDeviceManagement.GetLwm2mTypesCalls())

func (*DeviceManagementMock) GetOnlineDevices

func (mock *DeviceManagementMock) GetOnlineDevices(ctx context.Context, offset int, limit int) (models.Collection[models.Device], error)

GetOnlineDevices calls GetOnlineDevicesFunc.

func (*DeviceManagementMock) GetOnlineDevicesCalls

func (mock *DeviceManagementMock) GetOnlineDevicesCalls() []struct {
	Ctx    context.Context
	Offset int
	Limit  int
}

GetOnlineDevicesCalls gets all the calls that were made to GetOnlineDevices. Check the length with:

len(mockedDeviceManagement.GetOnlineDevicesCalls())

func (*DeviceManagementMock) GetTenants

func (mock *DeviceManagementMock) GetTenants(ctx context.Context) (models.Collection[string], error)

GetTenants calls GetTenantsFunc.

func (*DeviceManagementMock) GetTenantsCalls

func (mock *DeviceManagementMock) GetTenantsCalls() []struct {
	Ctx context.Context
}

GetTenantsCalls gets all the calls that were made to GetTenants. Check the length with:

len(mockedDeviceManagement.GetTenantsCalls())

func (*DeviceManagementMock) GetWithAlarmID

func (mock *DeviceManagementMock) GetWithAlarmID(ctx context.Context, alarmID string, tenants []string) (models.Device, error)

GetWithAlarmID calls GetWithAlarmIDFunc.

func (*DeviceManagementMock) GetWithAlarmIDCalls

func (mock *DeviceManagementMock) GetWithAlarmIDCalls() []struct {
	Ctx     context.Context
	AlarmID string
	Tenants []string
}

GetWithAlarmIDCalls gets all the calls that were made to GetWithAlarmID. Check the length with:

len(mockedDeviceManagement.GetWithAlarmIDCalls())

func (*DeviceManagementMock) GetWithinBounds

func (mock *DeviceManagementMock) GetWithinBounds(ctx context.Context, bounds models.Bounds) (models.Collection[models.Device], error)

GetWithinBounds calls GetWithinBoundsFunc.

func (*DeviceManagementMock) GetWithinBoundsCalls

func (mock *DeviceManagementMock) GetWithinBoundsCalls() []struct {
	Ctx    context.Context
	Bounds models.Bounds
}

GetWithinBoundsCalls gets all the calls that were made to GetWithinBounds. Check the length with:

len(mockedDeviceManagement.GetWithinBoundsCalls())

func (*DeviceManagementMock) Merge

func (mock *DeviceManagementMock) Merge(ctx context.Context, deviceID string, fields map[string]any, tenants []string) error

Merge calls MergeFunc.

func (*DeviceManagementMock) MergeCalls

func (mock *DeviceManagementMock) MergeCalls() []struct {
	Ctx      context.Context
	DeviceID string
	Fields   map[string]any
	Tenants  []string
}

MergeCalls gets all the calls that were made to Merge. Check the length with:

len(mockedDeviceManagement.MergeCalls())

func (*DeviceManagementMock) Query

func (mock *DeviceManagementMock) Query(ctx context.Context, params map[string][]string, tenants []string) (models.Collection[models.Device], error)

Query calls QueryFunc.

func (*DeviceManagementMock) QueryCalls

func (mock *DeviceManagementMock) QueryCalls() []struct {
	Ctx     context.Context
	Params  map[string][]string
	Tenants []string
}

QueryCalls gets all the calls that were made to Query. Check the length with:

len(mockedDeviceManagement.QueryCalls())

func (*DeviceManagementMock) Seed

func (mock *DeviceManagementMock) Seed(ctx context.Context, reader io.Reader, tenants []string) error

Seed calls SeedFunc.

func (*DeviceManagementMock) SeedCalls

func (mock *DeviceManagementMock) SeedCalls() []struct {
	Ctx     context.Context
	Reader  io.Reader
	Tenants []string
}

SeedCalls gets all the calls that were made to Seed. Check the length with:

len(mockedDeviceManagement.SeedCalls())

func (*DeviceManagementMock) Update

func (mock *DeviceManagementMock) Update(ctx context.Context, device models.Device) error

Update calls UpdateFunc.

func (*DeviceManagementMock) UpdateCalls

func (mock *DeviceManagementMock) UpdateCalls() []struct {
	Ctx    context.Context
	Device models.Device
}

UpdateCalls gets all the calls that were made to Update. Check the length with:

len(mockedDeviceManagement.UpdateCalls())

func (*DeviceManagementMock) UpdateState

func (mock *DeviceManagementMock) UpdateState(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error

UpdateState calls UpdateStateFunc.

func (*DeviceManagementMock) UpdateStateCalls

func (mock *DeviceManagementMock) UpdateStateCalls() []struct {
	Ctx         context.Context
	DeviceID    string
	Tenant      string
	DeviceState models.DeviceState
}

UpdateStateCalls gets all the calls that were made to UpdateState. Check the length with:

len(mockedDeviceManagement.UpdateStateCalls())

func (*DeviceManagementMock) UpdateStatus

func (mock *DeviceManagementMock) UpdateStatus(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error

UpdateStatus calls UpdateStatusFunc.

func (*DeviceManagementMock) UpdateStatusCalls

func (mock *DeviceManagementMock) UpdateStatusCalls() []struct {
	Ctx          context.Context
	DeviceID     string
	Tenant       string
	DeviceStatus models.DeviceStatus
}

UpdateStatusCalls gets all the calls that were made to UpdateStatus. Check the length with:

len(mockedDeviceManagement.UpdateStatusCalls())

type DeviceRepository

type DeviceRepository interface {
	GetDevice(ctx context.Context, conditions ...storage.ConditionFunc) (types.Device, error)
	QueryDevices(ctx context.Context, conditions ...storage.ConditionFunc) (types.Collection[types.Device], error)
	AddDevice(ctx context.Context, device types.Device) error
	UpdateDevice(ctx context.Context, device types.Device) error
	UpdateStatus(ctx context.Context, deviceID, tenant string, deviceStatus types.DeviceStatus) error
	UpdateState(ctx context.Context, deviceID, tenant string, deviceState types.DeviceState) error
	GetTenants(ctx context.Context) ([]string, error)
}

type DeviceRepositoryMock

type DeviceRepositoryMock struct {
	// AddDeviceFunc mocks the AddDevice method.
	AddDeviceFunc func(ctx context.Context, device models.Device) error

	// GetDeviceFunc mocks the GetDevice method.
	GetDeviceFunc func(ctx context.Context, conditions ...storage.ConditionFunc) (models.Device, error)

	// GetTenantsFunc mocks the GetTenants method.
	GetTenantsFunc func(ctx context.Context) ([]string, error)

	// QueryDevicesFunc mocks the QueryDevices method.
	QueryDevicesFunc func(ctx context.Context, conditions ...storage.ConditionFunc) (models.Collection[models.Device], error)

	// UpdateDeviceFunc mocks the UpdateDevice method.
	UpdateDeviceFunc func(ctx context.Context, device models.Device) error

	// UpdateStateFunc mocks the UpdateState method.
	UpdateStateFunc func(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error

	// UpdateStatusFunc mocks the UpdateStatus method.
	UpdateStatusFunc func(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error
	// contains filtered or unexported fields
}

DeviceRepositoryMock is a mock implementation of DeviceRepository.

func TestSomethingThatUsesDeviceRepository(t *testing.T) {

	// make and configure a mocked DeviceRepository
	mockedDeviceRepository := &DeviceRepositoryMock{
		AddDeviceFunc: func(ctx context.Context, device models.Device) error {
			panic("mock out the AddDevice method")
		},
		GetDeviceFunc: func(ctx context.Context, conditions ...storage.ConditionFunc) (models.Device, error) {
			panic("mock out the GetDevice method")
		},
		GetTenantsFunc: func(ctx context.Context) ([]string, error) {
			panic("mock out the GetTenants method")
		},
		QueryDevicesFunc: func(ctx context.Context, conditions ...storage.ConditionFunc) (models.Collection[models.Device], error) {
			panic("mock out the QueryDevices method")
		},
		UpdateDeviceFunc: func(ctx context.Context, device models.Device) error {
			panic("mock out the UpdateDevice method")
		},
		UpdateStateFunc: func(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error {
			panic("mock out the UpdateState method")
		},
		UpdateStatusFunc: func(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error {
			panic("mock out the UpdateStatus method")
		},
	}

	// use mockedDeviceRepository in code that requires DeviceRepository
	// and then make assertions.

}

func (*DeviceRepositoryMock) AddDevice

func (mock *DeviceRepositoryMock) AddDevice(ctx context.Context, device models.Device) error

AddDevice calls AddDeviceFunc.

func (*DeviceRepositoryMock) AddDeviceCalls

func (mock *DeviceRepositoryMock) AddDeviceCalls() []struct {
	Ctx    context.Context
	Device models.Device
}

AddDeviceCalls gets all the calls that were made to AddDevice. Check the length with:

len(mockedDeviceRepository.AddDeviceCalls())

func (*DeviceRepositoryMock) GetDevice

func (mock *DeviceRepositoryMock) GetDevice(ctx context.Context, conditions ...storage.ConditionFunc) (models.Device, error)

GetDevice calls GetDeviceFunc.

func (*DeviceRepositoryMock) GetDeviceCalls

func (mock *DeviceRepositoryMock) GetDeviceCalls() []struct {
	Ctx        context.Context
	Conditions []storage.ConditionFunc
}

GetDeviceCalls gets all the calls that were made to GetDevice. Check the length with:

len(mockedDeviceRepository.GetDeviceCalls())

func (*DeviceRepositoryMock) GetTenants

func (mock *DeviceRepositoryMock) GetTenants(ctx context.Context) ([]string, error)

GetTenants calls GetTenantsFunc.

func (*DeviceRepositoryMock) GetTenantsCalls

func (mock *DeviceRepositoryMock) GetTenantsCalls() []struct {
	Ctx context.Context
}

GetTenantsCalls gets all the calls that were made to GetTenants. Check the length with:

len(mockedDeviceRepository.GetTenantsCalls())

func (*DeviceRepositoryMock) QueryDevices

func (mock *DeviceRepositoryMock) QueryDevices(ctx context.Context, conditions ...storage.ConditionFunc) (models.Collection[models.Device], error)

QueryDevices calls QueryDevicesFunc.

func (*DeviceRepositoryMock) QueryDevicesCalls

func (mock *DeviceRepositoryMock) QueryDevicesCalls() []struct {
	Ctx        context.Context
	Conditions []storage.ConditionFunc
}

QueryDevicesCalls gets all the calls that were made to QueryDevices. Check the length with:

len(mockedDeviceRepository.QueryDevicesCalls())

func (*DeviceRepositoryMock) UpdateDevice

func (mock *DeviceRepositoryMock) UpdateDevice(ctx context.Context, device models.Device) error

UpdateDevice calls UpdateDeviceFunc.

func (*DeviceRepositoryMock) UpdateDeviceCalls

func (mock *DeviceRepositoryMock) UpdateDeviceCalls() []struct {
	Ctx    context.Context
	Device models.Device
}

UpdateDeviceCalls gets all the calls that were made to UpdateDevice. Check the length with:

len(mockedDeviceRepository.UpdateDeviceCalls())

func (*DeviceRepositoryMock) UpdateState

func (mock *DeviceRepositoryMock) UpdateState(ctx context.Context, deviceID string, tenant string, deviceState models.DeviceState) error

UpdateState calls UpdateStateFunc.

func (*DeviceRepositoryMock) UpdateStateCalls

func (mock *DeviceRepositoryMock) UpdateStateCalls() []struct {
	Ctx         context.Context
	DeviceID    string
	Tenant      string
	DeviceState models.DeviceState
}

UpdateStateCalls gets all the calls that were made to UpdateState. Check the length with:

len(mockedDeviceRepository.UpdateStateCalls())

func (*DeviceRepositoryMock) UpdateStatus

func (mock *DeviceRepositoryMock) UpdateStatus(ctx context.Context, deviceID string, tenant string, deviceStatus models.DeviceStatus) error

UpdateStatus calls UpdateStatusFunc.

func (*DeviceRepositoryMock) UpdateStatusCalls

func (mock *DeviceRepositoryMock) UpdateStatusCalls() []struct {
	Ctx          context.Context
	DeviceID     string
	Tenant       string
	DeviceStatus models.DeviceStatus
}

UpdateStatusCalls gets all the calls that were made to UpdateStatus. Check the length with:

len(mockedDeviceRepository.UpdateStatusCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL