github.com/rigado/snapd@v2.42.5-go-mod+incompatible/overlord/snapshotstate/backend/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 backend 21 22 import ( 23 "os" 24 "os/user" 25 26 "github.com/snapcore/snapd/osutil/sys" 27 ) 28 29 var ( 30 AddDirToZip = addDirToZip 31 TarAsUser = tarAsUser 32 PickUserWrapper = pickUserWrapper 33 ) 34 35 func MockIsTesting(newIsTesting bool) func() { 36 oldIsTesting := isTesting 37 isTesting = newIsTesting 38 return func() { 39 isTesting = oldIsTesting 40 } 41 } 42 43 func MockUserLookupId(newLookupId func(string) (*user.User, error)) func() { 44 oldLookupId := userLookupId 45 userLookupId = newLookupId 46 return func() { 47 userLookupId = oldLookupId 48 } 49 } 50 51 func MockOsOpen(newOsOpen func(string) (*os.File, error)) func() { 52 oldOsOpen := osOpen 53 osOpen = newOsOpen 54 return func() { 55 osOpen = oldOsOpen 56 } 57 } 58 59 func MockDirNames(newDirNames func(*os.File, int) ([]string, error)) func() { 60 oldDirNames := dirNames 61 dirNames = newDirNames 62 return func() { 63 dirNames = oldDirNames 64 } 65 } 66 67 func MockOpen(newOpen func(string) (*Reader, error)) func() { 68 oldOpen := backendOpen 69 backendOpen = newOpen 70 return func() { 71 backendOpen = oldOpen 72 } 73 } 74 75 func MockSysGeteuid(newGeteuid func() sys.UserID) (restore func()) { 76 oldGeteuid := sysGeteuid 77 sysGeteuid = newGeteuid 78 return func() { 79 sysGeteuid = oldGeteuid 80 } 81 } 82 83 func MockExecLookPath(newLookPath func(string) (string, error)) (restore func()) { 84 oldLookPath := execLookPath 85 execLookPath = newLookPath 86 return func() { 87 execLookPath = oldLookPath 88 } 89 } 90 91 func SetUserWrapper(newUserWrapper string) (restore func()) { 92 oldUserWrapper := userWrapper 93 userWrapper = newUserWrapper 94 return func() { 95 userWrapper = oldUserWrapper 96 } 97 }