github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/cmd/snap-recovery-chooser/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 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 main 21 22 import ( 23 "io" 24 "log/syslog" 25 "os/exec" 26 ) 27 28 var ( 29 OutputForUI = outputForUI 30 RunUI = runUI 31 Chooser = chooser 32 LoggerWithSyslogMaybe = loggerWithSyslogMaybe 33 ) 34 35 func MockStdStreams(stdout, stderr io.Writer) (restore func()) { 36 oldStdout, oldStderr := Stdout, Stderr 37 Stdout, Stderr = stdout, stderr 38 return func() { 39 Stdout, Stderr = oldStdout, oldStderr 40 } 41 } 42 43 func MockChooserTool(f func() (*exec.Cmd, error)) (restore func()) { 44 oldTool := chooserTool 45 chooserTool = f 46 return func() { 47 chooserTool = oldTool 48 } 49 } 50 51 func MockDefaultMarkerFile(p string) (restore func()) { 52 old := defaultMarkerFile 53 defaultMarkerFile = p 54 return func() { 55 defaultMarkerFile = old 56 } 57 } 58 59 func MockSyslogNew(f func(syslog.Priority, string) (io.Writer, error)) (restore func()) { 60 oldSyslogNew := syslogNew 61 syslogNew = f 62 return func() { 63 syslogNew = oldSyslogNew 64 } 65 }