github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/interfaces/ifacetest/spec.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 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 ifacetest 21 22 import ( 23 "github.com/snapcore/snapd/interfaces" 24 "github.com/snapcore/snapd/snap" 25 ) 26 27 // Specification is a specification intended for testing. 28 type Specification struct { 29 Snippets []string 30 } 31 32 // AddSnippet appends a snippet to a list stored in the specification. 33 func (spec *Specification) AddSnippet(snippet string) { 34 spec.Snippets = append(spec.Snippets, snippet) 35 } 36 37 // Implementation of methods required by interfaces.Specification 38 39 // AddConnectedPlug records test side-effects of having a connected plug. 40 func (spec *Specification) AddConnectedPlug(iface interfaces.Interface, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 41 type definer interface { 42 TestConnectedPlug(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error 43 } 44 if iface, ok := iface.(definer); ok { 45 return iface.TestConnectedPlug(spec, plug, slot) 46 } 47 return nil 48 } 49 50 // AddConnectedSlot records test side-effects of having a connected slot. 51 func (spec *Specification) AddConnectedSlot(iface interfaces.Interface, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 52 type definer interface { 53 TestConnectedSlot(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error 54 } 55 if iface, ok := iface.(definer); ok { 56 return iface.TestConnectedSlot(spec, plug, slot) 57 } 58 return nil 59 } 60 61 // AddPermanentPlug records test side-effects of having a plug. 62 func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *snap.PlugInfo) error { 63 type definer interface { 64 TestPermanentPlug(spec *Specification, plug *snap.PlugInfo) error 65 } 66 if iface, ok := iface.(definer); ok { 67 return iface.TestPermanentPlug(spec, plug) 68 } 69 return nil 70 } 71 72 // AddPermanentSlot records test side-effects of having a slot. 73 func (spec *Specification) AddPermanentSlot(iface interfaces.Interface, slot *snap.SlotInfo) error { 74 type definer interface { 75 TestPermanentSlot(spec *Specification, slot *snap.SlotInfo) error 76 } 77 if iface, ok := iface.(definer); ok { 78 return iface.TestPermanentSlot(spec, slot) 79 } 80 return nil 81 }