-
Notifications
You must be signed in to change notification settings - Fork 1
/
result_test.go
99 lines (81 loc) · 2.24 KB
/
result_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package scopes_test
import (
. "gopkg.in/check.v1"
"launchpad.net/go-unityscopes/v2"
)
func (s *S) TestResultSetURI(c *C) {
r := scopes.NewTestingResult()
c.Check(r.SetURI("http://example.com"), IsNil)
c.Check(r.URI(), Equals, "http://example.com")
var uri string
c.Check(r.Get("uri", &uri), IsNil)
c.Check(uri, Equals, "http://example.com")
}
func (s *S) TestResultSetTitle(c *C) {
r := scopes.NewTestingResult()
c.Check(r.SetTitle("The title"), IsNil)
c.Check(r.Title(), Equals, "The title")
var title string
c.Check(r.Get("title", &title), IsNil)
c.Check(title, Equals, "The title")
}
func (s *S) TestResultSetArt(c *C) {
r := scopes.NewTestingResult()
c.Check(r.SetArt("http://example.com/foo.png"), IsNil)
c.Check(r.Art(), Equals, "http://example.com/foo.png")
var uri string
c.Check(r.Get("art", &uri), IsNil)
c.Check(uri, Equals, "http://example.com/foo.png")
}
func (s *S) TestResultSetDndURI(c *C) {
r := scopes.NewTestingResult()
c.Check(r.SetDndURI("http://example.com"), IsNil)
c.Check(r.DndURI(), Equals, "http://example.com")
var uri string
c.Check(r.Get("dnd_uri", &uri), IsNil)
c.Check(uri, Equals, "http://example.com")
}
func (s *S) TestResultSetComplexValue(c *C) {
type Attr struct {
Value string `json:"value"`
}
r := scopes.NewTestingResult()
c.Check(r.Set("attributes", []Attr{
Attr{"one"},
Attr{"two"},
}), IsNil)
// Check that the value has been encoded as expeected:
var v interface{}
c.Check(r.Get("attributes", &v), IsNil)
c.Check(v, DeepEquals, []interface{}{
map[string]interface{}{"value": "one"},
map[string]interface{}{"value": "two"},
})
// The value can also be decoded into the complex structure too
var v2 []Attr
c.Check(r.Get("attributes", &v2), IsNil)
c.Check(v2, DeepEquals, []Attr{
Attr{"one"},
Attr{"two"},
})
}
func testMarshallingThisFunction(i int) int {
return i
}
func (s *S) TestResultSetBadValue(c *C) {
type Attr struct {
value int
value2 float64
}
r := scopes.NewTestingResult()
c.Check(r.Set("attributes", testMarshallingThisFunction), Not(Equals), nil)
}
func (s *S) TestResultGetBadValue(c *C) {
type Attr struct {
value int
value2 float64
}
r := scopes.NewTestingResult()
var attr string
c.Check(r.Get("bad_attribute", &attr), Not(Equals), nil)
}