iotagent

package
v0.0.0-...-edb1a23 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const UNKNOWN = "unknown"

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App interface {
	HandleSensorEvent(ctx context.Context, se application.SensorEvent) error
	HandleSensorMeasurementList(ctx context.Context, deviceID string, pack senml.Pack) error
	GetMeasurements(ctx context.Context, deviceID string, temprel string, t, et time.Time, lastN int) ([]application.Measurement, error)
	GetDevice(ctx context.Context, deviceID string) (dmc.Device, error)
}

func New

func New(dmc dmc.DeviceManagementClient, msgCtx messaging.MsgContext, store storage.Storage, createUnknownDeviceEnabled bool, createUnknownDeviceTenant string) App

type AppMock

type AppMock struct {
	// GetDeviceFunc mocks the GetDevice method.
	GetDeviceFunc func(ctx context.Context, deviceID string) (dmc.Device, error)

	// GetMeasurementsFunc mocks the GetMeasurements method.
	GetMeasurementsFunc func(ctx context.Context, deviceID string, temprel string, t time.Time, et time.Time, lastN int) ([]application.Measurement, error)

	// HandleSensorEventFunc mocks the HandleSensorEvent method.
	HandleSensorEventFunc func(ctx context.Context, se application.SensorEvent) error

	// HandleSensorMeasurementListFunc mocks the HandleSensorMeasurementList method.
	HandleSensorMeasurementListFunc func(ctx context.Context, deviceID string, pack senml.Pack) error
	// contains filtered or unexported fields
}

AppMock is a mock implementation of App.

func TestSomethingThatUsesApp(t *testing.T) {

	// make and configure a mocked App
	mockedApp := &AppMock{
		GetDeviceFunc: func(ctx context.Context, deviceID string) (dmc.Device, error) {
			panic("mock out the GetDevice method")
		},
		GetMeasurementsFunc: func(ctx context.Context, deviceID string, temprel string, t time.Time, et time.Time, lastN int) ([]application.Measurement, error) {
			panic("mock out the GetMeasurements method")
		},
		HandleSensorEventFunc: func(ctx context.Context, se application.SensorEvent) error {
			panic("mock out the HandleSensorEvent method")
		},
		HandleSensorMeasurementListFunc: func(ctx context.Context, deviceID string, pack senml.Pack) error {
			panic("mock out the HandleSensorMeasurementList method")
		},
	}

	// use mockedApp in code that requires App
	// and then make assertions.

}

func (*AppMock) GetDevice

func (mock *AppMock) GetDevice(ctx context.Context, deviceID string) (dmc.Device, error)

GetDevice calls GetDeviceFunc.

func (*AppMock) GetDeviceCalls

func (mock *AppMock) GetDeviceCalls() []struct {
	Ctx      context.Context
	DeviceID string
}

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

len(mockedApp.GetDeviceCalls())

func (*AppMock) GetMeasurements

func (mock *AppMock) GetMeasurements(ctx context.Context, deviceID string, temprel string, t time.Time, et time.Time, lastN int) ([]application.Measurement, error)

GetMeasurements calls GetMeasurementsFunc.

func (*AppMock) GetMeasurementsCalls

func (mock *AppMock) GetMeasurementsCalls() []struct {
	Ctx      context.Context
	DeviceID string
	Temprel  string
	T        time.Time
	Et       time.Time
	LastN    int
}

GetMeasurementsCalls gets all the calls that were made to GetMeasurements. Check the length with:

len(mockedApp.GetMeasurementsCalls())

func (*AppMock) HandleSensorEvent

func (mock *AppMock) HandleSensorEvent(ctx context.Context, se application.SensorEvent) error

HandleSensorEvent calls HandleSensorEventFunc.

func (*AppMock) HandleSensorEventCalls

func (mock *AppMock) HandleSensorEventCalls() []struct {
	Ctx context.Context
	Se  application.SensorEvent
}

HandleSensorEventCalls gets all the calls that were made to HandleSensorEvent. Check the length with:

len(mockedApp.HandleSensorEventCalls())

func (*AppMock) HandleSensorMeasurementList

func (mock *AppMock) HandleSensorMeasurementList(ctx context.Context, deviceID string, pack senml.Pack) error

HandleSensorMeasurementList calls HandleSensorMeasurementListFunc.

func (*AppMock) HandleSensorMeasurementListCalls

func (mock *AppMock) HandleSensorMeasurementListCalls() []struct {
	Ctx      context.Context
	DeviceID string
	Pack     senml.Pack
}

HandleSensorMeasurementListCalls gets all the calls that were made to HandleSensorMeasurementList. Check the length with:

len(mockedApp.HandleSensorMeasurementListCalls())

type StatusMessage

type StatusMessage struct {
	DeviceID     string    `json:"deviceID"`
	BatteryLevel int       `json:"batteryLevel"`
	Code         int       `json:"statusCode"`
	Messages     []string  `json:"statusMessages,omitempty"`
	Tenant       string    `json:"tenant"`
	Timestamp    time.Time `json:"timestamp"`
}

func (*StatusMessage) Body

func (m *StatusMessage) Body() []byte

func (*StatusMessage) ContentType

func (m *StatusMessage) ContentType() string

func (*StatusMessage) TopicName

func (m *StatusMessage) TopicName() string

Jump to

Keyboard shortcuts

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