github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/daemon/api_mock_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 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 daemon 21 22 import ( 23 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/interfaces" 26 "github.com/snapcore/snapd/overlord/snapstate" 27 "github.com/snapcore/snapd/snap" 28 "github.com/snapcore/snapd/snap/snaptest" 29 ) 30 31 func (s *apiSuite) mockSnap(c *C, yamlText string) *snap.Info { 32 if s.d == nil { 33 panic("call s.daemon(c) in your test first") 34 } 35 36 snapInfo := snaptest.MockSnap(c, yamlText, &snap.SideInfo{Revision: snap.R(1)}) 37 38 st := s.d.overlord.State() 39 40 st.Lock() 41 defer st.Unlock() 42 43 // Put a side info into the state 44 snapstate.Set(st, snapInfo.InstanceName(), &snapstate.SnapState{ 45 Active: true, 46 Sequence: []*snap.SideInfo{ 47 { 48 RealName: snapInfo.SnapName(), 49 Revision: snapInfo.Revision, 50 SnapID: "ididid", 51 }, 52 }, 53 Current: snapInfo.Revision, 54 SnapType: string(snapInfo.Type()), 55 }) 56 57 // Put the snap into the interface repository 58 repo := s.d.overlord.InterfaceManager().Repository() 59 err := repo.AddSnap(snapInfo) 60 c.Assert(err, IsNil) 61 return snapInfo 62 } 63 64 func (s *apiSuite) mockIface(c *C, iface interfaces.Interface) { 65 if s.d == nil { 66 panic("call s.daemon(c) in your test first") 67 } 68 err := s.d.overlord.InterfaceManager().Repository().AddInterface(iface) 69 c.Assert(err, IsNil) 70 } 71 72 var consumerYaml = ` 73 name: consumer 74 version: 1 75 apps: 76 app: 77 plugs: 78 plug: 79 interface: test 80 key: value 81 label: label 82 ` 83 84 var producerYaml = ` 85 name: producer 86 version: 1 87 apps: 88 app: 89 slots: 90 slot: 91 interface: test 92 key: value 93 label: label 94 ` 95 96 var coreProducerYaml = ` 97 name: core 98 version: 1 99 slots: 100 slot: 101 interface: test 102 key: value 103 label: label 104 ` 105 106 var differentProducerYaml = ` 107 name: producer 108 version: 1 109 apps: 110 app: 111 slots: 112 slot: 113 interface: different 114 key: value 115 label: label 116 ` 117 118 var configYaml = ` 119 name: config-snap 120 version: 1 121 hooks: 122 configure: 123 ` 124 var aliasYaml = ` 125 name: alias-snap 126 version: 1 127 apps: 128 app: 129 app2: 130 `