github.com/rigado/snapd@v2.42.5-go-mod+incompatible/overlord/snapstate/export_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016-2019 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 snapstate 21 22 import ( 23 "context" 24 "time" 25 26 "github.com/snapcore/snapd/overlord/state" 27 "github.com/snapcore/snapd/snap" 28 ) 29 30 type ManagerBackend managerBackend 31 32 func SetSnapManagerBackend(s *SnapManager, b ManagerBackend) { 33 s.backend = b 34 } 35 36 func MockSnapReadInfo(mock func(name string, si *snap.SideInfo) (*snap.Info, error)) (restore func()) { 37 old := snapReadInfo 38 snapReadInfo = mock 39 return func() { snapReadInfo = old } 40 } 41 42 func MockMountPollInterval(intv time.Duration) (restore func()) { 43 old := mountPollInterval 44 mountPollInterval = intv 45 return func() { mountPollInterval = old } 46 } 47 48 func MockRevisionDate(mock func(info *snap.Info) time.Time) (restore func()) { 49 old := revisionDate 50 if mock == nil { 51 mock = revisionDateImpl 52 } 53 revisionDate = mock 54 return func() { revisionDate = old } 55 } 56 57 func MockOpenSnapFile(mock func(path string, si *snap.SideInfo) (*snap.Info, snap.Container, error)) (restore func()) { 58 prevOpenSnapFile := openSnapFile 59 openSnapFile = mock 60 return func() { openSnapFile = prevOpenSnapFile } 61 } 62 63 func MockErrtrackerReport(mock func(string, string, string, map[string]string) (string, error)) (restore func()) { 64 prev := errtrackerReport 65 errtrackerReport = mock 66 return func() { errtrackerReport = prev } 67 } 68 69 func MockPrerequisitesRetryTimeout(d time.Duration) (restore func()) { 70 old := prerequisitesRetryTimeout 71 prerequisitesRetryTimeout = d 72 return func() { prerequisitesRetryTimeout = old } 73 } 74 75 func MockOsutilEnsureUserGroup(mock func(name string, id uint32, extraUsers bool) error) (restore func()) { 76 old := osutilEnsureUserGroup 77 osutilEnsureUserGroup = mock 78 return func() { osutilEnsureUserGroup = old } 79 } 80 81 var ( 82 CoreInfoInternal = coreInfo 83 CheckSnap = checkSnap 84 CanRemove = canRemove 85 CanDisable = canDisable 86 CachedStore = cachedStore 87 DefaultRefreshSchedule = defaultRefreshSchedule 88 DoInstall = doInstall 89 UserFromUserID = userFromUserID 90 ValidateFeatureFlags = validateFeatureFlags 91 ResolveChannel = resolveChannel 92 93 DefaultContentPlugProviders = defaultContentPlugProviders 94 95 HasOtherInstances = hasOtherInstances 96 ) 97 98 func PreviousSideInfo(snapst *SnapState) *snap.SideInfo { 99 return snapst.previousSideInfo() 100 } 101 102 // aliases v2 103 var ( 104 ApplyAliasesChange = applyAliasesChange 105 AutoAliasesDelta = autoAliasesDelta 106 RefreshAliases = refreshAliases 107 CheckAliasesConflicts = checkAliasesConflicts 108 DisableAliases = disableAliases 109 SwitchSummary = switchSummary 110 ) 111 112 // readme files 113 var ( 114 WriteSnapReadme = writeSnapReadme 115 SnapReadme = snapReadme 116 ) 117 118 // refreshes 119 var ( 120 NewAutoRefresh = newAutoRefresh 121 NewRefreshHints = newRefreshHints 122 CanRefreshOnMeteredConnection = canRefreshOnMeteredConnection 123 124 NewCatalogRefresh = newCatalogRefresh 125 CatalogRefreshDelayBase = catalogRefreshDelayBase 126 CatalogRefreshDelayWithDelta = catalogRefreshDelayWithDelta 127 ) 128 129 func MockNextRefresh(ar *autoRefresh, when time.Time) { 130 ar.nextRefresh = when 131 } 132 133 func MockLastRefreshSchedule(ar *autoRefresh, schedule string) { 134 ar.lastRefreshSchedule = schedule 135 } 136 137 func MockCatalogRefreshNextRefresh(cr *catalogRefresh, when time.Time) { 138 cr.nextCatalogRefresh = when 139 } 140 141 func NextCatalogRefresh(cr *catalogRefresh) time.Time { 142 return cr.nextCatalogRefresh 143 } 144 145 func MockRefreshRetryDelay(d time.Duration) func() { 146 origRefreshRetryDelay := refreshRetryDelay 147 refreshRetryDelay = d 148 return func() { 149 refreshRetryDelay = origRefreshRetryDelay 150 } 151 } 152 153 func MockIsOnMeteredConnection(mock func() (bool, error)) func() { 154 old := IsOnMeteredConnection 155 IsOnMeteredConnection = mock 156 return func() { 157 IsOnMeteredConnection = old 158 } 159 } 160 161 func MockLocalInstallCleanupWait(d time.Duration) (restore func()) { 162 old := localInstallCleanupWait 163 localInstallCleanupWait = d 164 return func() { 165 localInstallCleanupWait = old 166 } 167 } 168 169 func MockLocalInstallLastCleanup(t time.Time) (restore func()) { 170 old := localInstallLastCleanup 171 localInstallLastCleanup = t 172 return func() { 173 localInstallLastCleanup = old 174 } 175 } 176 177 // re-refresh related 178 var ( 179 RefreshedSnaps = refreshedSnaps 180 ReRefreshFilter = reRefreshFilter 181 ) 182 183 type UpdateFilter = updateFilter 184 185 func MockReRefreshUpdateMany(f func(context.Context, *state.State, []string, int, UpdateFilter, *Flags, string) ([]string, []*state.TaskSet, error)) (restore func()) { 186 old := reRefreshUpdateMany 187 reRefreshUpdateMany = f 188 return func() { 189 reRefreshUpdateMany = old 190 } 191 } 192 193 func MockReRefreshRetryTimeout(d time.Duration) (restore func()) { 194 old := reRefreshRetryTimeout 195 reRefreshRetryTimeout = d 196 return func() { 197 reRefreshRetryTimeout = old 198 } 199 } 200 201 // aux store info 202 var ( 203 AuxStoreInfoFilename = auxStoreInfoFilename 204 RetrieveAuxStoreInfo = retrieveAuxStoreInfo 205 KeepAuxStoreInfo = keepAuxStoreInfo 206 DiscardAuxStoreInfo = discardAuxStoreInfo 207 ) 208 209 type AuxStoreInfo = auxStoreInfo