github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/systemd/export_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 systemd 21 22 import ( 23 "io" 24 ) 25 26 var ( 27 Jctl = jctl 28 ) 29 30 func MockOsGetenv(f func(string) string) func() { 31 oldOsGetenv := osGetenv 32 osGetenv = f 33 return func() { osGetenv = oldOsGetenv } 34 } 35 36 func MockOsutilStreamCommand(f func(string, ...string) (io.ReadCloser, error)) func() { 37 old := osutilStreamCommand 38 osutilStreamCommand = f 39 return func() { osutilStreamCommand = old } 40 } 41 42 func MockJournalStdoutPath(path string) func() { 43 oldPath := journalStdoutPath 44 journalStdoutPath = path 45 return func() { 46 journalStdoutPath = oldPath 47 } 48 } 49 50 func MockOsutilIsMounted(f func(path string) (bool, error)) func() { 51 old := osutilIsMounted 52 osutilIsMounted = f 53 return func() { 54 osutilIsMounted = old 55 } 56 } 57 58 func MockSquashFsType(f func() (string, []string)) func() { 59 old := squashfsFsType 60 squashfsFsType = f 61 return func() { 62 squashfsFsType = old 63 } 64 } 65 66 func MockSystemdSysctlPath(p string) (restore func()) { 67 old := systemdSysctlPath 68 systemdSysctlPath = p 69 return func() { 70 systemdSysctlPath = old 71 } 72 } 73 74 func (e *Error) SetExitCode(i int) { 75 e.exitCode = i 76 } 77 78 func (e *Error) SetMsg(msg []byte) { 79 e.msg = msg 80 }