Debian Codegraph @

client/service/common_test.go

raw
1 /*
2 Copyright 2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 package service
18
19 import (
20 "github.com/godbus/dbus/v5"
21 . "gopkg.in/check.v1"
22
23 "gitlab.com/ubports/development/core/lomiri-push-service/click"
24 )
25
26 type commonSuite struct{}
27
28 var _ = Suite(&commonSuite{})
29
30 func (cs *commonSuite) TestGrabDBusPackageAndAppIdWorks(c *C) {
31 svc := new(DBusService)
32 msg := &dbus.Message{
33 Type: dbus.TypeMethodCall,
34 Headers: map[dbus.HeaderField]dbus.Variant{
35 dbus.FieldPath: dbus.MakeVariant("/com/lomiri/Postal/com_2eexample_2etest"),
36 },
37 }
38 aPackage := "com.example.test"
39 anAppId := aPackage + "_test"
40 app, err := svc.grabDBusPackageAndAppId(msg, anAppId)
41 c.Check(err, IsNil)
42 c.Check(app.Package, Equals, aPackage)
43 c.Check(app.Original(), Equals, anAppId)
44 }
45
46 type fakeInstalledChecker struct{}
47
48 func (fakeInstalledChecker) Installed(app *click.AppId, setVersion bool) bool {
49 return app.Original()[0] == 'c'
50 }
51
52 func (cs *commonSuite) TestGrabDBusPackageAndAppIdFails(c *C) {
53 svc := new(DBusService)
54 svc.installedChecker = fakeInstalledChecker{}
55 aDBusPath := "/com/lomiri/Postal/com_2eexample_2etest"
56 aPackage := "com.example.test"
57 anAppId := aPackage + "_test"
58
59 for i, s := range []struct {
60 path string
61 id string
62 errt error
63 }{
64 {aDBusPath, aPackage, click.ErrInvalidAppId},
65 {aDBusPath, "x" + anAppId, click.ErrMissingApp},
66 {aDBusPath, "c" + anAppId, ErrAppIdMismatch},
67 } {
68 comment := Commentf("iteration #%d", i)
69 msg := &dbus.Message{
70 Type: dbus.TypeMethodCall,
71 Headers: map[dbus.HeaderField]dbus.Variant{
72 dbus.FieldPath: dbus.MakeVariant(s.path),
73 },
74 }
75 app, err := svc.grabDBusPackageAndAppId(msg, s.id)
76 c.Check(err, Equals, s.errt, comment)
77 c.Check(app, IsNil, comment)
78 }
79 }