-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil_test.go
58 lines (48 loc) · 1.46 KB
/
util_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
54
55
56
57
58
package iot
import (
"testing"
)
func TestTimeStamp(t *testing.T) {
timeStamp := timeStamp()
if len(timeStamp) != 10 {
t.Error(`Time Stamp length must be 10`)
}
}
func TestDataCollectionTime(t *testing.T) {
if len(GetEventTimeStamp()) != 16 {
t.Errorf(`Data Collection Time length must be 16,but is %d`, len(GetEventTimeStamp()))
}
}
func TestHmacSha256(t *testing.T) {
encodedPassword := "c0fefa1341fb0647290e93f641a9bcea74cd32111668cdc5f7418553640a55cc"
if hmacSha256("123456789", "202012222200") != encodedPassword {
t.Errorf("encoded password must be %s but is %s", encodedPassword, hmacSha256("123456789", "202012222200"))
}
}
func TestInterface2JsonString(t *testing.T) {
if Interface2JsonString(nil) != "" {
t.Errorf("nill interface to json string must empty")
}
}
func TestGetTopicRequestId(t *testing.T) {
topic := "$os/device/down/request=123456789"
if getTopicRequestId(topic) != "123456789" {
t.Errorf("topic request id must be %s", "123456789")
}
}
func TestFormatTopic(t *testing.T) {
topic := "$os/device/{device_id}/up"
deviceId := "123"
formatTopicName := "$os/device/123/up"
if formatTopicName != formatTopic(topic, deviceId) {
t.Errorf("formated topic must be %s", formatTopicName)
}
}
// 仅适用于windows系统
func TestSmartFileName(t *testing.T) {
fileName := "D/go/sdk/test.log"
name := "D:\\go\\sdk\\test.log"
if name != smartFileName(fileName) {
t.Errorf("in windows file system,smart file name must be %s", name)
}
}