github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/interfaces/builtin/packagekit_control_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin_test 21 22 import ( 23 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/interfaces" 26 "github.com/snapcore/snapd/interfaces/apparmor" 27 "github.com/snapcore/snapd/interfaces/builtin" 28 "github.com/snapcore/snapd/snap" 29 "github.com/snapcore/snapd/testutil" 30 ) 31 32 type PackageKitControlInterfaceSuite struct { 33 iface interfaces.Interface 34 slot *interfaces.ConnectedSlot 35 slotInfo *snap.SlotInfo 36 plug *interfaces.ConnectedPlug 37 plugInfo *snap.PlugInfo 38 } 39 40 var _ = Suite(&PackageKitControlInterfaceSuite{ 41 iface: builtin.MustInterface("packagekit-control"), 42 }) 43 44 func (s *PackageKitControlInterfaceSuite) SetUpTest(c *C) { 45 const coreYaml = `name: core 46 version: 0 47 type: os 48 slots: 49 packagekit-control: 50 interface: packagekit-control 51 ` 52 s.slot, s.slotInfo = MockConnectedSlot(c, coreYaml, nil, "packagekit-control") 53 54 var consumerYaml = `name: consumer 55 version: 0 56 apps: 57 app: 58 plugs: [packagekit-control] 59 ` 60 s.plug, s.plugInfo = MockConnectedPlug(c, consumerYaml, nil, "packagekit-control") 61 } 62 63 func (s *PackageKitControlInterfaceSuite) TestName(c *C) { 64 c.Assert(s.iface.Name(), Equals, "packagekit-control") 65 } 66 67 func (s *PackageKitControlInterfaceSuite) TestSanitize(c *C) { 68 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 69 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 70 } 71 72 func (s *PackageKitControlInterfaceSuite) TestAppArmorConnectedPlug(c *C) { 73 spec := &apparmor.Specification{} 74 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 75 c.Assert(spec.SecurityTags(), HasLen, 1) 76 c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.freedesktop.PackageKit`) 77 c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.freedesktop.PackageKit.Offline`) 78 c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.freedesktop.PackageKit.Transaction`) 79 } 80 81 func (s *PackageKitControlInterfaceSuite) TestStaticInfo(c *C) { 82 si := interfaces.StaticInfoOf(s.iface) 83 c.Check(si.ImplicitOnCore, Equals, false) 84 c.Check(si.ImplicitOnClassic, Equals, true) 85 c.Check(si.Summary, Equals, "allows control of the PackageKit service") 86 c.Check(si.BaseDeclarationPlugs, testutil.Contains, "packagekit-control") 87 c.Check(si.BaseDeclarationSlots, testutil.Contains, "packagekit-control") 88 } 89 90 func (s *PackageKitControlInterfaceSuite) TestInterfaces(c *C) { 91 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 92 }