Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
interfaces: add new interface API #2613
Merged
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3904c17
interfaces: add new interface API
zyga 80adb8f
interfaces: fix typo
zyga 5bd9533
interfaces: use Interface rather than interface{} for recorders
zyga 2bd9b80
interfaces: rename Recorer to Specification
zyga 85e3515
interfaces: remove 'Record' from all the APIs
zyga 42a9a83
interfaces: return SecuritySystem from Name of each backend
zyga b8d2494
interfaces: add Repository.AddBackend
zyga fd34132
interfaces: add Specification to Backend interface
zyga e24d005
interfaces: call the test backend "test"
zyga 8368da3
interfaces: replace InterfacesAffectingSnap with SnapSpecification
zyga 67170bc
interfaces: add the Add prefix to Specification methods
zyga 4f88630
interfaces: rename recorder to spec in filenames
zyga ebf4da8
interfaces: tweak comments to match method names
zyga 7bd7e40
interfaces: document SnapSpecification better
zyga 8a176f9
interfaces: allow only relevant spec methods to be defined
zyga 15b9c9f
interfaces: tweak comments to refer to specifications
zyga bc04493
interfacecs: tweak comment
zyga a043b08
interfaces: correct copy-pasted comments
zyga cfb8c2c
interfacecs: rename backend.Specification to NewSpecification
zyga 0129045
interfaces: tweak error message not to mention specifcations
zyga d8acfec
interfaces/ifacetest: drop test from file names
zyga 5b122c7
interfaces: rename TestSpecification to just Specification
zyga 6effa66
interfaces/ifacetest: rename specification.go to just spec.go
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -55,8 +55,8 @@ import ( | ||
| type Backend struct{} | ||
| // Name returns the name of the backend. | ||
| -func (b *Backend) Name() string { | ||
| - return "apparmor" | ||
| +func (b *Backend) Name() interfaces.SecuritySystem { | ||
| + return interfaces.SecurityAppArmor | ||
| } | ||
| // Setup creates and loads apparmor profiles specific to a given snap. | ||
| @@ -205,3 +205,7 @@ func unloadProfiles(profiles []string) error { | ||
| } | ||
| return nil | ||
| } | ||
| + | ||
| +func (b *Backend) NewSpecification() interfaces.Specification { | ||
| + panic(fmt.Errorf("%s is not using specifications yet", b.Name())) | ||
zyga
Contributor
|
||
| +} | ||
| @@ -0,0 +1,80 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 2017 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +package ifacetest | ||
| + | ||
| +import ( | ||
| + "github.com/snapcore/snapd/interfaces" | ||
| +) | ||
| + | ||
| +// Specification is a specification intended for testing. | ||
| +type Specification struct { | ||
| + Snippets []string | ||
| +} | ||
| + | ||
| +// AddSnippet appends a snippet to a list stored in the specification. | ||
| +func (spec *Specification) AddSnippet(snippet string) { | ||
| + spec.Snippets = append(spec.Snippets, snippet) | ||
| +} | ||
| + | ||
| +// Implementation of methods required by interfaces.Specification | ||
| + | ||
| +// AddConnectedPlug records test side-effects of having a connected plug. | ||
| +func (spec *Specification) AddConnectedPlug(iface interfaces.Interface, plug *interfaces.Plug, slot *interfaces.Slot) error { | ||
| + type definer interface { | ||
| + TestConnectedPlug(spec *Specification, plug *interfaces.Plug, slot *interfaces.Slot) error | ||
| + } | ||
| + if iface, ok := iface.(definer); ok { | ||
| + return iface.TestConnectedPlug(spec, plug, slot) | ||
| + } | ||
| + return nil | ||
| +} | ||
| + | ||
| +// AddConnectedSlot records test side-effects of having a connected slot. | ||
| +func (spec *Specification) AddConnectedSlot(iface interfaces.Interface, plug *interfaces.Plug, slot *interfaces.Slot) error { | ||
| + type definer interface { | ||
| + TestConnectedSlot(spec *Specification, plug *interfaces.Plug, slot *interfaces.Slot) error | ||
| + } | ||
| + if iface, ok := iface.(definer); ok { | ||
| + return iface.TestConnectedSlot(spec, plug, slot) | ||
| + } | ||
| + return nil | ||
| +} | ||
| + | ||
| +// AddPermanentPlug records test side-effects of having a plug. | ||
| +func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *interfaces.Plug) error { | ||
| + type definer interface { | ||
| + TestPermanentPlug(spec *Specification, plug *interfaces.Plug) error | ||
| + } | ||
| + if iface, ok := iface.(definer); ok { | ||
| + return iface.TestPermanentPlug(spec, plug) | ||
| + } | ||
| + return nil | ||
| +} | ||
| + | ||
| +// AddPermanentSlot records test side-effects of having a slot. | ||
| +func (spec *Specification) AddPermanentSlot(iface interfaces.Interface, slot *interfaces.Slot) error { | ||
| + type definer interface { | ||
| + TestPermanentSlot(spec *Specification, slot *interfaces.Slot) error | ||
| + } | ||
| + if iface, ok := iface.(definer); ok { | ||
| + return iface.TestPermanentSlot(spec, slot) | ||
| + } | ||
| + return nil | ||
| +} |
| @@ -0,0 +1,93 @@ | ||
| +// -*- Mode: Go; indent-tabs-mode: t -*- | ||
| + | ||
| +/* | ||
| + * Copyright (C) 2015-2017 Canonical Ltd | ||
| + * | ||
| + * This program is free software: you can redistribute it and/or modify | ||
| + * it under the terms of the GNU General Public License version 3 as | ||
| + * published by the Free Software Foundation. | ||
| + * | ||
| + * This program is distributed in the hope that it will be useful, | ||
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + * GNU General Public License for more details. | ||
| + * | ||
| + * You should have received a copy of the GNU General Public License | ||
| + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| + * | ||
| + */ | ||
| + | ||
| +package ifacetest_test | ||
| + | ||
| +import ( | ||
| + . "gopkg.in/check.v1" | ||
| + | ||
| + "github.com/snapcore/snapd/interfaces" | ||
| + "github.com/snapcore/snapd/interfaces/ifacetest" | ||
| + "github.com/snapcore/snapd/snap" | ||
| +) | ||
| + | ||
| +type SpecificationSuite struct { | ||
| + iface *ifacetest.TestInterface | ||
| + spec *ifacetest.Specification | ||
| + plug *interfaces.Plug | ||
| + slot *interfaces.Slot | ||
| +} | ||
| + | ||
| +var _ = Suite(&SpecificationSuite{ | ||
| + iface: &ifacetest.TestInterface{ | ||
| + InterfaceName: "test", | ||
| + TestConnectedPlugCallback: func(spec *ifacetest.Specification, plug *interfaces.Plug, slot *interfaces.Slot) error { | ||
| + spec.AddSnippet("connected-plug") | ||
| + return nil | ||
| + }, | ||
| + TestConnectedSlotCallback: func(spec *ifacetest.Specification, plug *interfaces.Plug, slot *interfaces.Slot) error { | ||
| + spec.AddSnippet("connected-slot") | ||
| + return nil | ||
| + }, | ||
| + TestPermanentPlugCallback: func(spec *ifacetest.Specification, plug *interfaces.Plug) error { | ||
| + spec.AddSnippet("permanent-plug") | ||
| + return nil | ||
| + }, | ||
| + TestPermanentSlotCallback: func(spec *ifacetest.Specification, slot *interfaces.Slot) error { | ||
| + spec.AddSnippet("permanent-slot") | ||
| + return nil | ||
| + }, | ||
| + }, | ||
| + plug: &interfaces.Plug{ | ||
| + PlugInfo: &snap.PlugInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "snap"}, | ||
| + Name: "name", | ||
| + Interface: "test", | ||
| + }, | ||
| + }, | ||
| + slot: &interfaces.Slot{ | ||
| + SlotInfo: &snap.SlotInfo{ | ||
| + Snap: &snap.Info{SuggestedName: "snap"}, | ||
| + Name: "name", | ||
| + Interface: "test", | ||
| + }, | ||
| + }, | ||
| +}) | ||
| + | ||
| +func (s *SpecificationSuite) SetUpTest(c *C) { | ||
| + s.spec = &ifacetest.Specification{} | ||
| +} | ||
| + | ||
| +// AddSnippet is not broken | ||
| +func (s *SpecificationSuite) TestAddSnippet(c *C) { | ||
| + s.spec.AddSnippet("hello") | ||
| + s.spec.AddSnippet("world") | ||
| + c.Assert(s.spec.Snippets, DeepEquals, []string{"hello", "world"}) | ||
| +} | ||
| + | ||
| +// The Specification can be used through the interfaces.Specification interface | ||
| +func (s *SpecificationSuite) SpecificationIface(c *C) { | ||
| + var r interfaces.Specification = s.spec | ||
| + c.Assert(r.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil) | ||
| + c.Assert(r.AddConnectedSlot(s.iface, s.plug, s.slot), IsNil) | ||
| + c.Assert(r.AddPermanentPlug(s.iface, s.plug), IsNil) | ||
| + c.Assert(r.AddPermanentSlot(s.iface, s.slot), IsNil) | ||
| + c.Assert(s.spec.Snippets, DeepEquals, []string{ | ||
| + "connected-plug", "connected-slot", "permanent-plug", "permanent-slot"}) | ||
| +} |
Oops, something went wrong.
logger.Panicf(...)would probably be better