Merge lp:~kyrofa/unity-scope-snappy/finish_dbus_client_testing into lp:~unity-api-team/unity-scope-snappy/trunk

Proposed by Kyle Fazzari
Status: Merged
Approved by: dobey
Approved revision: 38
Merged at revision: 37
Proposed branch: lp:~kyrofa/unity-scope-snappy/finish_dbus_client_testing
Merge into: lp:~unity-api-team/unity-scope-snappy/trunk
Prerequisite: lp:~kyrofa/unity-scope-snappy/update_godbus_testability
Diff against target: 306 lines (+236/-3)
7 files modified
store/packages/dbus_connection.go (+30/-0)
store/packages/dbus_manager_client.go (+1/-1)
store/packages/dbus_manager_client_test.go (+58/-0)
store/packages/fakes/fake_dbus_connection.go (+37/-0)
store/packages/fakes/fake_dbus_connection_test.go (+45/-0)
store/packages/mocks/mock_bus_object.go (+65/-0)
test_coverage.sh (+0/-2)
To merge this branch: bzr merge lp:~kyrofa/unity-scope-snappy/finish_dbus_client_testing
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
dobey (community) Approve
Review via email: mp+266231@code.launchpad.net

Commit message

Finish testing dbus client in store scope.

Description of the change

Finish testing dbus client in store scope.

Now everything has 100% test coverage.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
36. By Kyle Fazzari

Merge prerequisite changes from lp:~kyrofa/unity-scope-snappy/update_godbus_testability.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
37. By Kyle Fazzari

Merge prerequisite changes from lp:~kyrofa/unity-scope-snappy/update_godbus_testability

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

Copyright headers in source files please.

38. By Kyle Fazzari

Add copyright file headers to new files.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'store/packages/dbus_connection.go'
2--- store/packages/dbus_connection.go 1970-01-01 00:00:00 +0000
3+++ store/packages/dbus_connection.go 2015-08-12 19:46:23 +0000
4@@ -0,0 +1,30 @@
5+/* Copyright (C) 2015 Canonical Ltd.
6+ *
7+ * This file is part of unity-scope-snappy.
8+ *
9+ * unity-scope-snappy is free software: you can redistribute it and/or modify it
10+ * under the terms of the GNU General Public License as published by the Free
11+ * Software Foundation, either version 3 of the License, or (at your option) any
12+ * later version.
13+ *
14+ * unity-scope-snappy is distributed in the hope that it will be useful, but
15+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17+ * details.
18+ *
19+ * You should have received a copy of the GNU General Public License along with
20+ * unity-scope-snappy. If not, see <http://www.gnu.org/licenses/>.
21+ */
22+
23+package packages
24+
25+import (
26+ "launchpad.net/unity-scope-snappy/internal/github.com/godbus/dbus"
27+)
28+
29+// DbusConnection is an interface of the DBus connection used by the DBus
30+// package manager client.
31+type DbusConnection interface {
32+ Names() []string
33+ Object(dest string, path dbus.ObjectPath) dbus.BusObject
34+}
35
36=== modified file 'store/packages/dbus_manager_client.go'
37--- store/packages/dbus_manager_client.go 2015-06-30 19:59:02 +0000
38+++ store/packages/dbus_manager_client.go 2015-08-12 19:46:23 +0000
39@@ -15,7 +15,7 @@
40 // DbusManagerClient is a DBus client for communicating with the WebDM Package
41 // Manager DBus service.
42 type DbusManagerClient struct {
43- connection *dbus.Conn // Connection to the dbus bus
44+ connection DbusConnection // Connection to the dbus bus
45
46 dbusObject string
47 dbusObjectInterface string
48
49=== modified file 'store/packages/dbus_manager_client_test.go'
50--- store/packages/dbus_manager_client_test.go 2015-06-30 18:32:04 +0000
51+++ store/packages/dbus_manager_client_test.go 2015-08-12 19:46:23 +0000
52@@ -1,6 +1,8 @@
53 package packages
54
55 import (
56+ "launchpad.net/unity-scope-snappy/store/packages/fakes"
57+ "launchpad.net/unity-scope-snappy/store/packages/mocks"
58 "testing"
59 )
60
61@@ -34,6 +36,34 @@
62 }
63 }
64
65+// Test typical Install usage.
66+func TestDbusManagerClient_install(t *testing.T) {
67+ client := NewDbusManagerClient()
68+ mockObject := &mocks.MockBusObject{}
69+ client.connection = fakes.FakeDbusConnection{mockObject}
70+
71+ _, err := client.Install("foo")
72+ if err != nil {
73+ t.Errorf("Unexpected error installing: %s", err)
74+ }
75+
76+ if !mockObject.CallCalled {
77+ t.Errorf("Expected client to call MockBusObject.Call")
78+ }
79+
80+ if mockObject.Method != client.installMethod {
81+ t.Errorf(`Client called method "%s", expected "%s"`, mockObject.Method, client.installMethod)
82+ }
83+
84+ if len(mockObject.Args) != 1 {
85+ t.Fatalf("Got %d arguments, expected 1", len(mockObject.Args))
86+ }
87+
88+ if mockObject.Args[0] != "foo" {
89+ t.Error(`Install was called with "%s", expected "foo"`, mockObject.Args[0])
90+ }
91+}
92+
93 // Test that trying to install before connecting results in an error.
94 func TestDbusManagerClient_install_beforeConnect(t *testing.T) {
95 client := NewDbusManagerClient()
96@@ -43,6 +73,34 @@
97 }
98 }
99
100+// Test typical Uninstall usage.
101+func TestDbusManagerClient_uninstall(t *testing.T) {
102+ client := NewDbusManagerClient()
103+ mockObject := &mocks.MockBusObject{}
104+ client.connection = fakes.FakeDbusConnection{mockObject}
105+
106+ _, err := client.Uninstall("foo")
107+ if err != nil {
108+ t.Errorf("Unexpected error installing: %s", err)
109+ }
110+
111+ if !mockObject.CallCalled {
112+ t.Errorf("Expected client to call MockBusObject.Call")
113+ }
114+
115+ if mockObject.Method != client.uninstallMethod {
116+ t.Errorf(`Client called method "%s", expected "%s"`, mockObject.Method, client.uninstallMethod)
117+ }
118+
119+ if len(mockObject.Args) != 1 {
120+ t.Fatalf("Got %d arguments, expected 1", len(mockObject.Args))
121+ }
122+
123+ if mockObject.Args[0] != "foo" {
124+ t.Error(`Uninstall was called with "%s", expected "foo"`, mockObject.Args[0])
125+ }
126+}
127+
128 // Test that trying to uninstall before connecting results in an error.
129 func TestDbusManagerClient_uninstall_beforeConnect(t *testing.T) {
130 client := NewDbusManagerClient()
131
132=== added file 'store/packages/fakes/fake_dbus_connection.go'
133--- store/packages/fakes/fake_dbus_connection.go 1970-01-01 00:00:00 +0000
134+++ store/packages/fakes/fake_dbus_connection.go 2015-08-12 19:46:23 +0000
135@@ -0,0 +1,37 @@
136+/* Copyright (C) 2015 Canonical Ltd.
137+ *
138+ * This file is part of unity-scope-snappy.
139+ *
140+ * unity-scope-snappy is free software: you can redistribute it and/or modify it
141+ * under the terms of the GNU General Public License as published by the Free
142+ * Software Foundation, either version 3 of the License, or (at your option) any
143+ * later version.
144+ *
145+ * unity-scope-snappy is distributed in the hope that it will be useful, but
146+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
148+ * details.
149+ *
150+ * You should have received a copy of the GNU General Public License along with
151+ * unity-scope-snappy. If not, see <http://www.gnu.org/licenses/>.
152+ */
153+
154+package fakes
155+
156+import (
157+ "launchpad.net/unity-scope-snappy/internal/github.com/godbus/dbus"
158+)
159+
160+// DbusConnection is an interface of the DBus connection used by the DBus
161+// package manager client.
162+type FakeDbusConnection struct {
163+ DbusObject dbus.BusObject
164+}
165+
166+func (fake FakeDbusConnection) Names() []string {
167+ return []string{":1.42"}
168+}
169+
170+func (fake FakeDbusConnection) Object(dest string, path dbus.ObjectPath) dbus.BusObject {
171+ return fake.DbusObject
172+}
173
174=== added file 'store/packages/fakes/fake_dbus_connection_test.go'
175--- store/packages/fakes/fake_dbus_connection_test.go 1970-01-01 00:00:00 +0000
176+++ store/packages/fakes/fake_dbus_connection_test.go 2015-08-12 19:46:23 +0000
177@@ -0,0 +1,45 @@
178+/* Copyright (C) 2015 Canonical Ltd.
179+ *
180+ * This file is part of unity-scope-snappy.
181+ *
182+ * unity-scope-snappy is free software: you can redistribute it and/or modify it
183+ * under the terms of the GNU General Public License as published by the Free
184+ * Software Foundation, either version 3 of the License, or (at your option) any
185+ * later version.
186+ *
187+ * unity-scope-snappy is distributed in the hope that it will be useful, but
188+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
189+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
190+ * details.
191+ *
192+ * You should have received a copy of the GNU General Public License along with
193+ * unity-scope-snappy. If not, see <http://www.gnu.org/licenses/>.
194+ */
195+
196+package fakes
197+
198+import (
199+ "launchpad.net/unity-scope-snappy/store/packages/mocks"
200+ "reflect"
201+ "testing"
202+)
203+
204+// Test that Names returns a single name
205+func TestFakeDbusConnection_names(t *testing.T) {
206+ connection := FakeDbusConnection{}
207+
208+ names := connection.Names()
209+ if len(names) != 1 {
210+ t.Fatalf("Got %d names, expected 1", len(names))
211+ }
212+}
213+
214+// Test that Object simply returns the given DbusObject.
215+func TestFakeDbusConnection_object(t *testing.T) {
216+ mock := &mocks.MockBusObject{}
217+ connection := FakeDbusConnection{mock}
218+
219+ if !reflect.DeepEqual(connection.Object("foo", "bar"), mock) {
220+ t.Error("Expected the fake connection to return the given mock")
221+ }
222+}
223
224=== added directory 'store/packages/mocks'
225=== added file 'store/packages/mocks/mock_bus_object.go'
226--- store/packages/mocks/mock_bus_object.go 1970-01-01 00:00:00 +0000
227+++ store/packages/mocks/mock_bus_object.go 2015-08-12 19:46:23 +0000
228@@ -0,0 +1,65 @@
229+/* Copyright (C) 2015 Canonical Ltd.
230+ *
231+ * This file is part of unity-scope-snappy.
232+ *
233+ * unity-scope-snappy is free software: you can redistribute it and/or modify it
234+ * under the terms of the GNU General Public License as published by the Free
235+ * Software Foundation, either version 3 of the License, or (at your option) any
236+ * later version.
237+ *
238+ * unity-scope-snappy is distributed in the hope that it will be useful, but
239+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
240+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
241+ * details.
242+ *
243+ * You should have received a copy of the GNU General Public License along with
244+ * unity-scope-snappy. If not, see <http://www.gnu.org/licenses/>.
245+ */
246+
247+package mocks
248+
249+import (
250+ "launchpad.net/unity-scope-snappy/internal/github.com/godbus/dbus"
251+)
252+
253+// MockBusObject is a mocked implementation of the dbus.BusObject interface, for
254+// use within tests.
255+type MockBusObject struct {
256+ CallCalled bool
257+ GoCalled bool
258+ GetPropertyCalled bool
259+ DestinationCalled bool
260+ PathCalled bool
261+
262+ Method string
263+ Args []interface{}
264+}
265+
266+func (mock *MockBusObject) Call(method string, flags dbus.Flags, args ...interface{}) *dbus.Call {
267+ mock.CallCalled = true
268+ mock.Method = method
269+ mock.Args = args
270+ return &dbus.Call{Body: []interface{}{dbus.ObjectPath("/foo/1")}}
271+}
272+
273+func (mock *MockBusObject) Go(method string, flags dbus.Flags, ch chan *dbus.Call, args ...interface{}) *dbus.Call {
274+ mock.GoCalled = true
275+ mock.Method = method
276+ mock.Args = args
277+ return &dbus.Call{Body: []interface{}{dbus.ObjectPath("/foo/1")}}
278+}
279+
280+func (mock *MockBusObject) GetProperty(p string) (dbus.Variant, error) {
281+ mock.GetPropertyCalled = true
282+ return dbus.MakeVariant("foo"), nil
283+}
284+
285+func (mock *MockBusObject) Destination() string {
286+ mock.DestinationCalled = true
287+ return "foo"
288+}
289+
290+func (mock *MockBusObject) Path() dbus.ObjectPath {
291+ mock.PathCalled = true
292+ return dbus.ObjectPath("/foo/1")
293+}
294
295=== modified file 'test_coverage.sh'
296--- test_coverage.sh 2015-07-15 16:34:50 +0000
297+++ test_coverage.sh 2015-08-12 19:46:23 +0000
298@@ -63,8 +63,6 @@
299
300 get_coverages $coverage_final $@
301
302-echo "Cov type: $coverage_type"
303-
304 if [ "$coverage_type" == "xml" ]; then
305 gocov convert $coverage_final | gocov-xml > coverage.xml
306 elif [ "$coverage_type" == "html" ]; then

Subscribers

People subscribed via source and target branches