gitee.com/mysnapcore/mysnapd@v0.1.0/sandbox/apparmor/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2014-2015 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 apparmor 21 22 import ( 23 "io" 24 "os" 25 26 "gitee.com/mysnapcore/mysnapd/osutil" 27 "gitee.com/mysnapcore/mysnapd/testutil" 28 ) 29 30 var ( 31 NumberOfJobsParam = numberOfJobsParam 32 ) 33 34 func MockRuntimeNumCPU(new func() int) (restore func()) { 35 old := runtimeNumCPU 36 runtimeNumCPU = new 37 return func() { 38 runtimeNumCPU = old 39 } 40 } 41 42 func MockMkdirAll(f func(string, os.FileMode) error) func() { 43 r := testutil.Backup(&osMkdirAll) 44 osMkdirAll = f 45 return r 46 } 47 48 func MockAtomicWrite(f func(string, io.Reader, os.FileMode, osutil.AtomicWriteFlags) error) func() { 49 r := testutil.Backup(&osutilAtomicWrite) 50 osutilAtomicWrite = f 51 return r 52 } 53 54 func MockLoadProfiles(f func([]string, string, AaParserFlags) error) func() { 55 r := testutil.Backup(&LoadProfiles) 56 LoadProfiles = f 57 return r 58 } 59 60 func MockSnapConfineDistroProfilePath(f func() string) func() { 61 r := testutil.Backup(&SnapConfineDistroProfilePath) 62 SnapConfineDistroProfilePath = f 63 return r 64 } 65 66 // MockProfilesPath mocks the file read by LoadedProfiles() 67 func MockProfilesPath(t *testutil.BaseTest, profiles string) { 68 profilesPath = profiles 69 t.AddCleanup(func() { 70 profilesPath = realProfilesPath 71 }) 72 } 73 74 func MockFsRootPath(path string) (restorer func()) { 75 old := rootPath 76 rootPath = path 77 return func() { 78 rootPath = old 79 } 80 } 81 82 func MockParserSearchPath(new string) (restore func()) { 83 oldAppArmorParserSearchPath := parserSearchPath 84 parserSearchPath = new 85 return func() { 86 parserSearchPath = oldAppArmorParserSearchPath 87 } 88 } 89 90 var ( 91 ProbeKernelFeatures = probeKernelFeatures 92 ProbeParserFeatures = probeParserFeatures 93 94 RequiredKernelFeatures = requiredKernelFeatures 95 RequiredParserFeatures = requiredParserFeatures 96 PreferredKernelFeatures = preferredKernelFeatures 97 PreferredParserFeatures = preferredParserFeatures 98 ) 99 100 func FreshAppArmorAssessment() { 101 appArmorAssessment = &appArmorAssess{appArmorProber: &appArmorProbe{}} 102 }