gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/usersession/agent/export_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 agent 21 22 import ( 23 "syscall" 24 "time" 25 ) 26 27 var ( 28 SessionInfoCmd = sessionInfoCmd 29 ServiceControlCmd = serviceControlCmd 30 PendingRefreshNotificationCmd = pendingRefreshNotificationCmd 31 ) 32 33 func MockStopTimeouts(stop, kill time.Duration) (restore func()) { 34 oldStopTimeout := stopTimeout 35 stopTimeout = stop 36 oldKillWait := killWait 37 killWait = kill 38 return func() { 39 stopTimeout = oldStopTimeout 40 killWait = oldKillWait 41 } 42 } 43 44 func MockUcred(ucred *syscall.Ucred, err error) (restore func()) { 45 old := sysGetsockoptUcred 46 sysGetsockoptUcred = func(fd, level, opt int) (*syscall.Ucred, error) { 47 return ucred, err 48 } 49 return func() { 50 sysGetsockoptUcred = old 51 } 52 } 53 54 // MockNoBus temporarily unsets the D-Bus connection of a SessionAgent 55 func MockNoBus(agent *SessionAgent) (restore func()) { 56 bus := agent.bus 57 agent.bus = nil 58 return func() { 59 agent.bus = bus 60 } 61 }