github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/daemon/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 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 "net/http" 24 "time" 25 26 "github.com/snapcore/snapd/overlord" 27 "github.com/snapcore/snapd/overlord/hookstate" 28 "github.com/snapcore/snapd/overlord/servicestate" 29 "github.com/snapcore/snapd/overlord/state" 30 "github.com/snapcore/snapd/snap" 31 ) 32 33 type Resp = resp 34 type ErrorResult = errorResult 35 36 var MinLane = minLane 37 38 func NewWithOverlord(o *overlord.Overlord) *Daemon { 39 d := &Daemon{overlord: o} 40 d.addRoutes() 41 return d 42 } 43 44 func MockMuxVars(vars func(*http.Request) map[string]string) (restore func()) { 45 old := muxVars 46 muxVars = vars 47 return func() { 48 muxVars = old 49 } 50 } 51 52 func MockBuildID(mock string) (restore func()) { 53 old := buildID 54 buildID = mock 55 return func() { 56 buildID = old 57 } 58 } 59 60 func MockShutdownTimeout(tm time.Duration) (restore func()) { 61 old := shutdownTimeout 62 shutdownTimeout = tm 63 return func() { 64 shutdownTimeout = old 65 } 66 } 67 68 func MockServicestateControl(f func(st *state.State, appInfos []*snap.AppInfo, inst *servicestate.Instruction, context *hookstate.Context) ([]*state.TaskSet, error)) (restore func()) { 69 old := servicestateControl 70 servicestateControl = f 71 return func() { 72 servicestateControl = old 73 } 74 }