~artmello/ubuntu-push/ubuntu-push-fix_1611848

« back to all changes in this revision

Viewing changes to bus/urfkill/urfkill_test.go

  • Committer: CI Train Bot
  • Author(s): Ricardo Salveti de Araujo
  • Date: 2015-04-30 15:08:54 UTC
  • mfrom: (145.1.2 ubuntu-push)
  • Revision ID: ci-train-bot@canonical.com-20150430150854-2u38lu0oi8rtomo1
[ Samuele Pedroni ]
* switch poller to use killswitch state for WLAN instead of misleading NM property (LP: #1446584)
* don't have goroutines from a previous test overlap with the next, races gets detected otherwise
* have the TestDialWorksDirect* tests quickly timeout, go1.3 wants a ServerName set in the tls config for them to work
* fix flaky test
* support sha384/512 certs, some exercizing of that
* let send a build number with acceptanceclient
* add helper to get int out of ConnectMsg Info
Approved by: Samuele Pedroni

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import (
20
20
        "testing"
21
21
 
22
 
        //"launchpad.net/go-dbus/v1"
 
22
        "launchpad.net/go-dbus/v1"
23
23
        . "launchpad.net/gocheck"
24
24
 
25
25
        testingbus "launchpad.net/ubuntu-push/bus/testing"
42
42
}
43
43
 
44
44
func (s *URSuite) TestNew(c *C) {
45
 
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), s.log)
 
45
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), nil, s.log)
46
46
        c.Check(ur, NotNil)
47
47
}
48
48
 
49
49
// IsFlightMode returns the right state when everything works
50
50
func (s *URSuite) TestIsFlightMode(c *C) {
51
51
        endp := testingbus.NewTestingEndpoint(nil, condition.Work(true), true)
52
 
        ur := New(endp, s.log)
 
52
        ur := New(endp, nil, s.log)
53
53
        state := ur.IsFlightMode()
54
54
        c.Check(state, Equals, true)
55
55
        callArgs := testingbus.GetCallArgs(endp)
60
60
 
61
61
// IsFlightMode returns the right state when dbus fails
62
62
func (s *URSuite) TestIsFlightModeFail(c *C) {
63
 
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
 
63
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
64
64
        state := ur.IsFlightMode()
65
65
        c.Check(state, Equals, false)
66
66
}
68
68
// IsFlightMode returns the right state when dbus works but delivers
69
69
// rubbish values
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)
74
74
}
75
75
 
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)
81
81
}
83
83
// WatchFightMode sends a stream of states over the channel
84
84
func (s *URSuite) TestWatchFlightMode(c *C) {
85
85
        tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), false, true, false)
86
 
        ur := New(tc, s.log)
 
86
        ur := New(tc, nil, s.log)
87
87
        ch, w, err := ur.WatchFlightMode()
88
88
        c.Assert(err, IsNil)
89
89
        defer w.Cancel()
93
93
 
94
94
// WatchFlightMode returns on error if the dbus call fails
95
95
func (s *URSuite) TestWatchFlightModeFails(c *C) {
96
 
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
 
96
        ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
97
97
        _, _, err := ur.WatchFlightMode()
98
98
        c.Check(err, NotNil)
99
99
}
101
101
// WatchFlightMode calls close on its channel when the watch bails
102
102
func (s *URSuite) TestWatchFlightModeClosesOnWatchBail(c *C) {
103
103
        tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
104
 
        ur := New(tc, s.log)
 
104
        ur := New(tc, nil, s.log)
105
105
        ch, w, err := ur.WatchFlightMode()
106
106
        c.Assert(err, IsNil)
107
107
        defer w.Cancel()
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, s.log)
 
115
        ur := New(tc, nil, s.log)
116
116
        ch, w, err := ur.WatchFlightMode()
117
117
        c.Assert(err, IsNil)
118
118
        defer w.Cancel()
119
119
        _, ok := <-ch
120
120
        c.Check(ok, Equals, false)
121
121
}
 
122
 
 
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)
 
128
}
 
129
 
 
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)
 
135
}
 
136
 
 
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)
 
142
}
 
143
 
 
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)
 
149
}
 
150
 
 
151
func mkWLANKillswitchStateMap(st KillswitchState) map[string]dbus.Variant {
 
152
        m := make(map[string]dbus.Variant)
 
153
        m["state"] = dbus.Variant{int32(st)}
 
154
        return m
 
155
}
 
156
 
 
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{}},
 
163
        )
 
164
        ur := New(nil, tc, s.log)
 
165
        ch, w, err := ur.WatchWLANKillswitchState()
 
166
        c.Assert(err, IsNil)
 
167
        defer w.Cancel()
 
168
        l := []KillswitchState{<-ch, <-ch, <-ch}
 
169
        c.Check(l, DeepEquals, []KillswitchState{KillswitchStateUnblocked, KillswitchStateHardBlocked, KillswitchStateUnblocked})
 
170
}
 
171
 
 
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()
 
176
        c.Check(err, NotNil)
 
177
}
 
178
 
 
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()
 
184
        c.Assert(err, IsNil)
 
185
        defer w.Cancel()
 
186
        _, ok := <-ch
 
187
        c.Check(ok, Equals, false)
 
188
}
 
189
 
 
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{}},
 
195
        )
 
196
        ur := New(nil, tc, s.log)
 
197
        ch, w, err := ur.WatchWLANKillswitchState()
 
198
        c.Assert(err, IsNil)
 
199
        defer w.Cancel()
 
200
        v, ok := <-ch
 
201
        c.Check(ok, Equals, true)
 
202
        c.Check(v, Equals, KillswitchStateUnblocked)
 
203
}
 
204
 
 
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{}},
 
210
        )
 
211
        ur := New(nil, tc, s.log)
 
212
        ch, w, err := ur.WatchWLANKillswitchState()
 
213
        c.Assert(err, IsNil)
 
214
        defer w.Cancel()
 
215
        v, ok := <-ch
 
216
        c.Check(ok, Equals, true)
 
217
        c.Check(v, Equals, KillswitchStateSoftBlocked)
 
218
}