68
68
// IsFlightMode returns the right state when dbus works but delivers
70
70
func (s *URSuite) TestIsFlightModeRubbishValues(c *C) {
71
ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
71
ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), nil, s.log)
72
72
state := ur.IsFlightMode()
73
73
c.Check(state, Equals, false)
76
76
// IsFlightMode returns the right state when dbus works but delivers a rubbish structure
77
77
func (s *URSuite) TestIsFlightModeRubbishStructure(c *C) {
78
ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
78
ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), nil, s.log)
79
79
state := ur.IsFlightMode()
80
80
c.Check(state, Equals, false)
112
112
// WatchFlightMode survives rubbish values
113
113
func (s *URSuite) TestWatchFlightModeSurvivesRubbishValues(c *C) {
114
114
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), "gorp")
115
ur := New(tc, nil, s.log)
116
116
ch, w, err := ur.WatchFlightMode()
117
117
c.Assert(err, IsNil)
120
120
c.Check(ok, Equals, false)
123
// GetWLANKillState returns the right state when everything works
124
func (s *URSuite) TestGetWLANKillState(c *C) {
125
ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), KillswitchStateSoftBlocked), s.log)
126
st := ur.GetWLANKillswitchState()
127
c.Check(st, Equals, KillswitchStateSoftBlocked)
130
// GetWLANKillswitchState returns the right state when dbus fails
131
func (s *URSuite) TestGetWLANKillswitchStateFail(c *C) {
132
ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
133
st := ur.GetWLANKillswitchState()
134
c.Check(st, Equals, KillswitchStateUnblocked)
137
// GetWLANKillswitchState returns the right state when dbus works but delivers rubbish values
138
func (s *URSuite) TestGetWLANKillswitchStateRubbishValues(c *C) {
139
ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
140
st := ur.GetWLANKillswitchState()
141
c.Check(st, Equals, KillswitchStateUnblocked)
144
// GetWLANKillswitchState returns the right state when dbus works but delivers a rubbish structure
145
func (s *URSuite) TestGetWLANKillswitchStateRubbishStructure(c *C) {
146
ur := New(nil, testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
147
st := ur.GetWLANKillswitchState()
148
c.Check(st, Equals, KillswitchStateUnblocked)
151
func mkWLANKillswitchStateMap(st KillswitchState) map[string]dbus.Variant {
152
m := make(map[string]dbus.Variant)
153
m["state"] = dbus.Variant{int32(st)}
157
// WatchWLANKillswitchState sends a stream of WLAN killswitch states over the channel
158
func (s *URSuite) TestWatchWLANKillswitchState(c *C) {
159
tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
160
[]interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
161
[]interface{}{mkWLANKillswitchStateMap(KillswitchStateHardBlocked), []string{}},
162
[]interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
164
ur := New(nil, tc, s.log)
165
ch, w, err := ur.WatchWLANKillswitchState()
168
l := []KillswitchState{<-ch, <-ch, <-ch}
169
c.Check(l, DeepEquals, []KillswitchState{KillswitchStateUnblocked, KillswitchStateHardBlocked, KillswitchStateUnblocked})
172
// WatchWLANKillswitchState returns on error if the dbus call fails
173
func (s *URSuite) TestWatchWLANKillswitchStateFails(c *C) {
174
ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
175
_, _, err := ur.WatchWLANKillswitchState()
179
// WatchWLANKillswitchState calls close on its channel when the watch bails
180
func (s *URSuite) TestWatchWLANKillswitchStateClosesOnWatchBail(c *C) {
181
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
182
ur := New(nil, tc, s.log)
183
ch, w, err := ur.WatchWLANKillswitchState()
187
c.Check(ok, Equals, false)
190
// WatchWLANKillswitchState ignores non-WLAN-killswitch PropertiesChanged
191
func (s *URSuite) TestWatchWLANKillswitchStateIgnoresIrrelevant(c *C) {
192
tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
193
[]interface{}{map[string]dbus.Variant{"foo": dbus.Variant{}}, []string{}},
194
[]interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
196
ur := New(nil, tc, s.log)
197
ch, w, err := ur.WatchWLANKillswitchState()
201
c.Check(ok, Equals, true)
202
c.Check(v, Equals, KillswitchStateUnblocked)
205
// WatchWLANKillswitchState ignores rubbish WLAN killswitch state
206
func (s *URSuite) TestWatchWLANKillswitchStateIgnoresRubbishValues(c *C) {
207
tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
208
[]interface{}{map[string]dbus.Variant{"state": dbus.Variant{-12}}, []string{}},
209
[]interface{}{mkWLANKillswitchStateMap(KillswitchStateSoftBlocked), []string{}},
211
ur := New(nil, tc, s.log)
212
ch, w, err := ur.WatchWLANKillswitchState()
216
c.Check(ok, Equals, true)
217
c.Check(v, Equals, KillswitchStateSoftBlocked)