gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/system_backup_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 "gitee.com/mysnapcore/mysnapd/interfaces" 26 "gitee.com/mysnapcore/mysnapd/interfaces/apparmor" 27 "gitee.com/mysnapcore/mysnapd/interfaces/builtin" 28 "gitee.com/mysnapcore/mysnapd/release" 29 "gitee.com/mysnapcore/mysnapd/snap" 30 "gitee.com/mysnapcore/mysnapd/testutil" 31 ) 32 33 type systemBackupInterfaceSuite struct { 34 testutil.BaseTest 35 36 iface interfaces.Interface 37 slotInfo *snap.SlotInfo 38 slot *interfaces.ConnectedSlot 39 plugInfo *snap.PlugInfo 40 plug *interfaces.ConnectedPlug 41 } 42 43 var _ = Suite(&systemBackupInterfaceSuite{ 44 iface: builtin.MustInterface("system-backup"), 45 }) 46 47 const systemBackupConsumerYaml = `name: consumer 48 version: 0 49 apps: 50 app: 51 plugs: [system-backup] 52 ` 53 54 const systemBackupCoreYaml = `name: core 55 version: 0 56 type: os 57 slots: 58 system-backup: 59 ` 60 61 func (s *systemBackupInterfaceSuite) SetUpTest(c *C) { 62 s.plug, s.plugInfo = MockConnectedPlug(c, systemBackupConsumerYaml, nil, "system-backup") 63 s.slot, s.slotInfo = MockConnectedSlot(c, systemBackupCoreYaml, nil, "system-backup") 64 } 65 66 func (s *systemBackupInterfaceSuite) TestName(c *C) { 67 c.Assert(s.iface.Name(), Equals, "system-backup") 68 } 69 70 func (s *systemBackupInterfaceSuite) TestSanitizeSlot(c *C) { 71 c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil) 72 } 73 74 func (s *systemBackupInterfaceSuite) TestSanitizePlug(c *C) { 75 c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil) 76 } 77 78 func (s *systemBackupInterfaceSuite) TestAppArmorSpec(c *C) { 79 restore := release.MockOnClassic(false) 80 defer restore() 81 82 spec := &apparmor.Specification{} 83 c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) 84 c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"}) 85 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `capability dac_read_search,`) 86 c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `# Description: Allow read-only access to the entire system`) 87 } 88 89 func (s *systemBackupInterfaceSuite) TestStaticInfo(c *C) { 90 si := interfaces.StaticInfoOf(s.iface) 91 c.Assert(si.ImplicitOnCore, Equals, true) 92 c.Assert(si.ImplicitOnClassic, Equals, true) 93 c.Assert(si.Summary, Equals, `allows read-only access to the entire system for backups`) 94 c.Assert(si.BaseDeclarationSlots, testutil.Contains, "system-backup") 95 } 96 97 func (s *systemBackupInterfaceSuite) TestAutoConnect(c *C) { 98 c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true) 99 } 100 101 func (s *systemBackupInterfaceSuite) TestInterfaces(c *C) { 102 c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface) 103 }