232
232
c.Check(ok, Equals, true)
233
233
c.Check(v, Equals, "42")
236
// GetWirelessEnabled returns the right state when everything works
237
func (s *NMSuite) TestGetWirelessEnabled(c *C) {
238
nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), false), s.log)
239
en := nm.GetWirelessEnabled()
240
c.Check(en, Equals, false)
243
// GetWirelessEnabled returns the right state when dbus fails
244
func (s *NMSuite) TestGetWirelessEnabledFail(c *C) {
245
nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
246
en := nm.GetWirelessEnabled()
247
c.Check(en, Equals, true)
250
// GetWirelessEnabled returns the right state when dbus works but delivers rubbish values
251
func (s *NMSuite) TestGetWirelessEnabledRubbishValues(c *C) {
252
nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
253
en := nm.GetWirelessEnabled()
254
c.Check(en, Equals, true)
257
// GetWirelessEnabled returns the right state when dbus works but delivers a rubbish structure
258
func (s *NMSuite) TestGetWirelessEnabledRubbishStructure(c *C) {
259
nm := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
260
en := nm.GetWirelessEnabled()
261
c.Check(en, Equals, true)
264
func mkWirelessEnMap(en bool) map[string]dbus.Variant {
265
m := make(map[string]dbus.Variant)
266
m["WirelessEnabled"] = dbus.Variant{en}
270
// WatchWirelessEnabled sends a stream of wireless enabled states over the channel
271
func (s *NMSuite) TestWatchWirelessEnabled(c *C) {
272
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true),
273
mkWirelessEnMap(true),
274
mkWirelessEnMap(false),
275
mkWirelessEnMap(true),
278
ch, w, err := nm.WatchWirelessEnabled()
281
l := []bool{<-ch, <-ch, <-ch}
282
c.Check(l, DeepEquals, []bool{true, false, true})
285
// WatchWirelessEnabled returns on error if the dbus call fails
286
func (s *NMSuite) TestWatchWirelessEnabledFails(c *C) {
287
nm := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
288
_, _, err := nm.WatchWirelessEnabled()
292
// WatchWirelessEnabled calls close on its channel when the watch bails
293
func (s *NMSuite) TestWatchWirelessEnabledClosesOnWatchBail(c *C) {
294
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
296
ch, w, err := nm.WatchWirelessEnabled()
300
c.Check(ok, Equals, false)
303
// WatchWirelessEnabled survives rubbish values
304
func (s *NMSuite) TestWatchWirelessEnabledSurvivesRubbishValues(c *C) {
305
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), "gorp")
307
ch, w, err := nm.WatchWirelessEnabled()
311
c.Check(ok, Equals, false)
314
// WatchWirelessEnabled ignores non-WirelessEnabled PropertyChanged
315
func (s *NMSuite) TestWatchWirelessEnabledIgnoresIrrelephant(c *C) {
316
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true),
317
map[string]dbus.Variant{"foo": dbus.Variant{}},
318
map[string]dbus.Variant{"WirelessEnabled": dbus.Variant{true}},
321
ch, w, err := nm.WatchWirelessEnabled()
325
c.Check(ok, Equals, true)
326
c.Check(v, Equals, true)
329
// WatchWirelessEnabled ignores rubbish WirelessEnabled
330
func (s *NMSuite) TestWatchWirelessEnabledIgnoresRubbishValues(c *C) {
331
tc := testingbus.NewTestingEndpoint(nil, condition.Work(true),
332
map[string]dbus.Variant{"WirelessEnabled": dbus.Variant{-12}},
333
map[string]dbus.Variant{"WirelessEnabled": dbus.Variant{false}},
336
ch, w, err := nm.WatchWirelessEnabled()
340
c.Check(ok, Equals, true)
341
c.Check(v, Equals, false)