-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcoreresource_test.go
70 lines (62 loc) · 1.61 KB
/
coreresource_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
59
60
61
62
63
64
65
66
67
68
69
70
package canopus
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCoreResourceParsing(t *testing.T) {
cases1 := []struct {
in string
elemCount int
targets []string
attrCount []int
attributes []map[string]string
}{
{
"</1>,</2>,</3>,</4>,</5/0>,</5/1>,</5/2>,</5/3>",
8,
[]string{"/1", "/2", "/3", "/4", "/5/0", "/5/1", "/5/2", "/5/3"},
[]int{0, 0, 0, 0, 0, 0, 0, 0, 0},
nil,
},
{
"</sensors>;ct=40;title=\"Sensor Index\",</sensors/temp>;rt=\"temperature-c\";if=\"sensor\",</sensors/light>;rt=\"light-lux\";if=\"sensor\",<http://www.example.com/sensors/t123>;anchor=\"/sensors/temp\";rel=\"describedby\",</t>;anchor=\"/sensors/temp\";rel=\"alternate\"",
5,
[]string{"/sensors", "/sensors/temp", "/sensors/light", "http://www.example.com/sensors/t123", "/t"},
[]int{1, 2, 2, 2, 2},
[]map[string]string{
map[string]string{
"ct": "40",
"title": "Sensor Index",
},
map[string]string{
"rt": "temperature-c",
"if": "sensor",
},
map[string]string{
"rt": "light-lux",
"if": "sensor",
},
map[string]string{
"anchor": "/sensors/temp",
"rel": "describedby",
},
map[string]string{
"anchor": "/sensors/temp",
"rel": "alternate",
},
},
},
}
for _, c := range cases1 {
resources := CoreResourcesFromString(c.in)
assert.Equal(t, len(resources), c.elemCount)
for i, o := range resources {
assert.Equal(t, o.Target, c.targets[i])
for _, a := range o.Attributes {
key := a.Key
val := a.Value
assert.Equal(t, c.attributes[i][key], val)
}
}
}
}