util

package module
v0.0.0-...-e21e7c9 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0, EPL-2.0 Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (

	// StartSendEvents specifies that events should be received.
	StartSendEvents SubscribeEventType = "START-SEND-EVENTS"

	// StopSendEvents specifies that events should no longer be received.
	StopSendEvents UnsubscribeEventType = "STOP-SEND-EVENTS"

	// StartSendMessages specifies that messages should be received.
	StartSendMessages SubscribeEventType = "START-SEND-MESSAGES"

	// StopSendMessages specifies that messages should no longer be received.
	StopSendMessages UnsubscribeEventType = "STOP-SEND-MESSAGES"
)

Variables

This section is empty.

Functions

func CombineErrors

func CombineErrors(errors []error) error

CombineErrors combine multiple errors in one error.

func Convert

func Convert(from interface{}, to interface{}) error

Convert marshals an object(e.g. map) to a JSON payload and unmarshals it to the given structure

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies source file to the destination.

func DeleteResources

func DeleteResources(cfg *TestConfiguration, resources []*Resource, deviceID, url, user, pass string) error

DeleteResources deletes all given resources and all related devices.

func ExecuteOperation

func ExecuteOperation(cfg *TestConfiguration, featureURL string, operation string, params interface{}) ([]byte, error)

ExecuteOperation executes an operation of a feature

func GetFeatureInboxMessagePath

func GetFeatureInboxMessagePath(featureID string, name string) string

GetFeatureInboxMessagePath returns the path to an inbox message of a feature

func GetFeatureOutboxMessagePath

func GetFeatureOutboxMessagePath(featureID string, name string) string

GetFeatureOutboxMessagePath returns the path to an outbox message of a feature

func GetFeaturePropertyPath

func GetFeaturePropertyPath(featureID string, name string) string

GetFeaturePropertyPath returns the path to a property on a feature

func GetFeaturePropertyValue

func GetFeaturePropertyValue(cfg *TestConfiguration, featureURL string, property string) ([]byte, error)

GetFeaturePropertyValue gets the value of a feature's property

func GetFeatureURL

func GetFeatureURL(thingURL string, featureID string) string

GetFeatureURL returns the url of a feature

func GetLiveMessageTopic

func GetLiveMessageTopic(fullThingID string, action protocol.TopicAction) string

GetLiveMessageTopic returns the live message topic

func GetThingURL

func GetThingURL(digitalTwinAPIAddress string, thingID string) string

GetThingURL returns the url of a thing

func GetTwinEventTopic

func GetTwinEventTopic(fullThingID string, action protocol.TopicAction) string

GetTwinEventTopic returns the twin event topic

func MillisToDuration

func MillisToDuration(millis int) time.Duration

MillisToDuration converts milliseconds to Duration

func NewDigitalTwinWSConnection

func NewDigitalTwinWSConnection(cfg *TestConfiguration) (*websocket.Conn, error)

NewDigitalTwinWSConnection creates a new WebSocket connection

func NewMQTTClient

func NewMQTTClient(cfg *TestConfiguration) (MQTT.Client, error)

NewMQTTClient creates a new MQTT client and connects it to the broker from the test configuration

func ProcessWSMessages

func ProcessWSMessages(cfg *TestConfiguration, ws *websocket.Conn, process func(*protocol.Envelope) (bool, error)) error

ProcessWSMessages processes messages for the satisfied condition from the WebSocket session or timeout expires

func RegisterDeviceResources

func RegisterDeviceResources(cfg *TestConfiguration,
	resources []*Resource, deviceID, url, user, pass string) error

RegisterDeviceResources registers all given resources. In case of error all resources registered by this function will be deleted.

func SendDeviceRegistryRequest

func SendDeviceRegistryRequest(payload []byte, method string, url string, username string, password string) ([]byte, error)

SendDeviceRegistryRequest sends a new HTTP request to the Ditto API

func SendDigitalTwinRequest

func SendDigitalTwinRequest(cfg *TestConfiguration, method string, url string, body interface{}) ([]byte, error)

SendDigitalTwinRequest sends a new HTTP request to the Ditto REST API

func SendMQTTMessage

func SendMQTTMessage(cfg *TestConfiguration, client MQTT.Client, topic string, message interface{}) error

SendMQTTMessage sends a message to a topic using specified client. The message is serialized to JSON format.

func SubscribeForWSMessages

func SubscribeForWSMessages(cfg *TestConfiguration, conn *websocket.Conn, eventType SubscribeEventType, filter string) error

SubscribeForWSMessages subscribes for the messages that are sent from a WebSocket session and awaits confirmation response.

func UnsubscribeFromWSMessages

func UnsubscribeFromWSMessages(cfg *TestConfiguration, ws *websocket.Conn, eventType UnsubscribeEventType) error

UnsubscribeFromWSMessages unsubscribes from the messages that are sent from a WebSocket session and awaits confirmation response.

func WaitForWSMessage

func WaitForWSMessage(cfg *TestConfiguration, ws *websocket.Conn, expectedMessage string) error

WaitForWSMessage waits for received a specific message from a WebSocket session or timeout expires

func WriteConfigFile

func WriteConfigFile(path string, cfg interface{}) error

WriteConfigFile writes interface data to the path file, creating it if necessary.

Types

type BootstrapConfiguration

type BootstrapConfiguration struct {
	LogFile             string   `json:"logFile"`
	PostBootstrapFile   string   `json:"postBootstrapFile"`
	PostBootstrapScript []string `json:"postBootstrapScript"`
	CaCert              string   `json:"caCert"`
	Address             string   `json:"address"`
	TenantID            string   `json:"tenantId"`
	DeviceID            string   `json:"deviceId"`
	AuthID              string   `json:"authId"`
	Password            string   `json:"password"`
}

BootstrapConfiguration holds the required configuration to suite bootstrapping to connect and where to receive post bootstrapping files and script.

type ConnectorConfiguration

type ConnectorConfiguration struct {
	CaCert   string `json:"caCert"`
	LogFile  string `json:"logFile"`
	Address  string `json:"address"`
	TenantID string `json:"tenantId"`
	DeviceID string `json:"deviceId"`
	AuthID   string `json:"authId"`
	Password string `json:"password"`
}

ConnectorConfiguration holds the minimum required configuration to suite connector to connect.

type Resource

type Resource struct {
	URL string

	Method string
	Body   string

	User string
	Pass string

	Delete bool
}

Resource holds all needed properties to create resources for the device.

func CreateDeviceResources

func CreateDeviceResources(newDeviceID, tenantID, policyID, password, registryAPI,
	registryAPIUsername, registryAPIPassword string, cfg *TestConfiguration) []*Resource

CreateDeviceResources creates device resources.

type SubscribeEventType

type SubscribeEventType string

SubscribeEventType is an event type description to be used with SubscribeForWSMessages. It specifies the type of messages which should be listened for.

type SuiteInitializer

type SuiteInitializer struct {
	Cfg *TestConfiguration

	ThingCfg *ThingConfiguration

	DittoClient *ditto.Client
	MQTTClient  MQTT.Client
}

SuiteInitializer is testify Suite initialization helper

func (*SuiteInitializer) Setup

func (suite *SuiteInitializer) Setup(t *testing.T)

Setup establishes connections to the local MQTT broker and Ditto

func (*SuiteInitializer) TearDown

func (suite *SuiteInitializer) TearDown()

TearDown closes all connections

type TestConfiguration

type TestConfiguration struct {
	LocalBroker              string `env:"LOCAL_BROKER" envDefault:"tcp://localhost:1883"`
	MQTTQuiesceMS            int    `env:"MQTT_QUIESCE_MS" envDefault:"500"`
	MQTTAcknowledgeTimeoutMS int    `env:"MQTT_ACKNOWLEDGE_TIMEOUT_MS" envDefault:"3000"`
	MQTTConnectMS            int    `env:"MQTT_CONNECT_TIMEOUT_MS" envDefault:"30000"`

	DigitalTwinAPIAddress  string `env:"DIGITAL_TWIN_API_ADDRESS"`
	DigitalTwinAPIUsername string `env:"DIGITAL_TWIN_API_USERNAME" envDefault:"ditto"`
	DigitalTwinAPIPassword string `env:"DIGITAL_TWIN_API_PASSWORD" envDefault:"ditto"`

	WSEventTimeoutMS int `env:"WS_EVENT_TIMEOUT_MS" envDefault:"30000"`
}

TestConfiguration is a common integration test configuration

type ThingConfiguration

type ThingConfiguration struct {
	DeviceID string `json:"deviceId"`
	TenantID string `json:"tenantId"`
	PolicyID string `json:"policyId"`
}

ThingConfiguration represents information about the configured thing

func GetThingConfiguration

func GetThingConfiguration(cfg *TestConfiguration, mqttClient MQTT.Client) (*ThingConfiguration, error)

GetThingConfiguration retrieves information about the configured thing

type UnsubscribeEventType

type UnsubscribeEventType string

UnsubscribeEventType is an event type description to be used with UnsubscribeFromWSMessages. It specifies the type of messages which should no longer be listened for.

Jump to

Keyboard shortcuts

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