gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/scsi_generic_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 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 "fmt" 24 25 . "gopkg.in/check.v1" 26 27 "gitee.com/mysnapcore/mysnapd/dirs" 28 "gitee.com/mysnapcore/mysnapd/interfaces" 29 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 30 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 31 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 32 "gitee.com/mysnapcore/mysnapd/snap" 33 "gitee.com/mysnapcore/mysnapd/snap/snaptest" 34 "gitee.com/mysnapcore/mysnapd/testutil" 35 ) 36 37 type ScsiGenericInterfaceSuite struct { 38 iface interfaces.Interface 39 slotInfo *snap.SlotInfo 40 slot *interfaces.ConnectedSlot 41 plugInfo *snap.PlugInfo 42 plug *interfaces.ConnectedPlug 43 } 44 45 var _ = Suite(&ScsiGenericInterfaceSuite{ 46 iface: builtin.MustInterface("scsi-generic"), 47 }) 48 49 func (s *ScsiGenericInterfaceSuite) SetUpTest(c *C) { 50 var mockPlugSnapInfoYaml = `name: other 51 version: 1.0 52 apps: 53 app: 54 command: foo 55 plugs: [scsi-generic] 56 ` 57 s.slotInfo = &snap.SlotInfo{ 58 Snap: &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS}, 59 Name: "scsi-generic", 60 Interface: "scsi-generic", 61 } 62 s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil) 63 snapInfo := snaptest.MockInfo(c, mockPlugSnapInfoYaml, nil) 64 s.plugInfo = snapInfo.Plugs["scsi-generic"] 65 s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil) 66 } 67 68 func (s *ScsiGenericInterfaceSuite) TestName(c *C) { 69 c.Assert(s.iface.Name(), Equals, "scsi-generic") 70 } 71 72 func (s *ScsiGenericInterfaceSuite) TestSanitizeSlot(c *C) { 73 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 74 } 75 76 func (s *ScsiGenericInterfaceSuite) TestSanitizePlug(c *C) { 77 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 78 } 79 80 func (s *ScsiGenericInterfaceSuite) TestUsedSecuritySystems(c *C) { 81 // connected plugs have a non-nil security snippet for apparmor 82 apparmorSpec := &apparmor.Specification{} 83 err := apparmorSpec.AddConnectedPlug(s.iface, s.plug, s.slot) 84 c.Assert(err, IsNil) 85 c.Assert(apparmorSpec.SecurityTags(), DeepEquals, []string{"snap.other.app"}) 86 c.Assert(apparmorSpec.SnippetForTag("snap.other.app"), testutil.Contains, "/dev/sg[0-9]* rw") 87 } 88 89 func (s *ScsiGenericInterfaceSuite) TestUDevSpec(c *C) { 90 udevSpec := &udev.Specification{} 91 c.Assert(udevSpec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 92 c.Assert(udevSpec.Snippets(), HasLen, 2) 93 c.Assert(udevSpec.Snippets(), testutil.Contains, `# scsi-generic 94 KERNEL=="sg[0-9]*", TAG+="snap_other_app"`) 95 c.Assert(udevSpec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_other_app", RUN+="%v/snap-device-helper $env{ACTION} snap_other_app $devpath $major:$minor"`, dirs.DistroLibExecDir)) 96 } 97 98 func (s *ScsiGenericInterfaceSuite) TestInterfaces(c *C) { 99 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 100 } 101 102 func (s *ScsiGenericInterfaceSuite) TestStaticInfo(c *C) { 103 si := interfaces.StaticInfoOf(s.iface) 104 c.Assert(si.ImplicitOnCore, Equals, true) 105 c.Assert(si.ImplicitOnClassic, Equals, true) 106 c.Assert(si.Summary, Equals, `allows access to SCSI generic driver devices`) 107 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "scsi-generic") 108 }