github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/gadget/install/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 install 21 22 import ( 23 "time" 24 25 "github.com/snapcore/snapd/gadget" 26 "github.com/snapcore/snapd/secboot" 27 ) 28 29 var ( 30 EnsureLayoutCompatibility = ensureLayoutCompatibility 31 DeviceFromRole = deviceFromRole 32 NewEncryptedDevice = newEncryptedDevice 33 34 MakeFilesystem = makeFilesystem 35 WriteContent = writeContent 36 MountFilesystem = mountFilesystem 37 38 CreateMissingPartitions = createMissingPartitions 39 RemoveCreatedPartitions = removeCreatedPartitions 40 EnsureNodesExist = ensureNodesExist 41 ) 42 43 func MockContentMountpoint(new string) (restore func()) { 44 old := contentMountpoint 45 contentMountpoint = new 46 return func() { 47 contentMountpoint = old 48 } 49 } 50 51 func MockSysMount(f func(source, target, fstype string, flags uintptr, data string) error) (restore func()) { 52 old := sysMount 53 sysMount = f 54 return func() { 55 sysMount = old 56 } 57 } 58 59 func MockSysUnmount(f func(target string, flags int) error) (restore func()) { 60 old := sysUnmount 61 sysUnmount = f 62 return func() { 63 sysUnmount = old 64 } 65 } 66 67 func MockEnsureNodesExist(f func(dss []gadget.OnDiskStructure, timeout time.Duration) error) (restore func()) { 68 old := ensureNodesExist 69 ensureNodesExist = f 70 return func() { 71 ensureNodesExist = old 72 } 73 } 74 75 func MockSecbootFormatEncryptedDevice(f func(key secboot.EncryptionKey, label, node string) error) (restore func()) { 76 old := secbootFormatEncryptedDevice 77 secbootFormatEncryptedDevice = f 78 return func() { 79 secbootFormatEncryptedDevice = old 80 } 81 } 82 83 func MockSecbootAddRecoveryKey(f func(key secboot.EncryptionKey, rkey secboot.RecoveryKey, node string) error) (restore func()) { 84 old := secbootAddRecoveryKey 85 secbootAddRecoveryKey = f 86 return func() { 87 secbootAddRecoveryKey = old 88 } 89 }