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