-
Notifications
You must be signed in to change notification settings - Fork 4
/
device_test.go
53 lines (45 loc) · 1.09 KB
/
device_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package iot
import (
uuid "github.com/satori/go.uuid"
"testing"
)
func TestIotDevice_SendMessage(t *testing.T) {
device := createIotDevice()
device.Init()
message := Message{
ObjectDeviceId: uuid.NewV4().String(),
Name: "Fist send message to platform",
Id: uuid.NewV4().String(),
Content: "Hello Huawei IoT Platform",
}
if !device.SendMessage(message) {
t.Errorf("device send message failed")
}
}
func TestIotDevice_ReportProperties(t *testing.T) {
device := createIotDevice()
device.Init()
props := DevicePropertyEntry{
ServiceId: "value",
EventTime: GetEventTimeStamp(),
Properties: struct {
Value string `json:"value"`
MsgType string `json:"msgType"`
}{
Value: "Test Report",
MsgType: "123",
},
}
var content []DevicePropertyEntry
content = append(content, props)
services := DeviceProperties{
Services: content,
}
reportResult := device.ReportProperties(services)
if !reportResult {
t.Error("device report property failed")
}
}
func createIotDevice() Device {
return CreateIotDevice(deviceId, devicePwd, server)
}