github.com/rigado/snapd@v2.42.5-go-mod+incompatible/overlord/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016 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 overlord
    21  
    22  import (
    23  	"time"
    24  
    25  	"github.com/snapcore/snapd/overlord/configstate"
    26  	"github.com/snapcore/snapd/overlord/hookstate"
    27  	"github.com/snapcore/snapd/overlord/snapstate"
    28  	"github.com/snapcore/snapd/overlord/state"
    29  	"github.com/snapcore/snapd/overlord/storecontext"
    30  	"github.com/snapcore/snapd/store"
    31  )
    32  
    33  // MockEnsureInterval sets the overlord ensure interval for tests.
    34  func MockEnsureInterval(d time.Duration) (restore func()) {
    35  	old := ensureInterval
    36  	ensureInterval = d
    37  	return func() { ensureInterval = old }
    38  }
    39  
    40  // MockPruneInterval sets the overlord prune interval for tests.
    41  func MockPruneInterval(prunei, prunew, abortw time.Duration) (restore func()) {
    42  	oldPruneInterval := pruneInterval
    43  	oldPruneWait := pruneWait
    44  	oldAbortWait := abortWait
    45  	pruneInterval = prunei
    46  	pruneWait = prunew
    47  	abortWait = abortw
    48  	return func() {
    49  		pruneInterval = oldPruneInterval
    50  		pruneWait = oldPruneWait
    51  		abortWait = oldAbortWait
    52  	}
    53  }
    54  
    55  // MockEnsureNext sets o.ensureNext for tests.
    56  func MockEnsureNext(o *Overlord, t time.Time) {
    57  	o.ensureNext = t
    58  }
    59  
    60  // Engine exposes the state engine in an Overlord for tests.
    61  func (o *Overlord) Engine() *StateEngine {
    62  	return o.stateEng
    63  }
    64  
    65  // NewStore exposes newStore.
    66  func (o *Overlord) NewStore(devBE storecontext.DeviceBackend) snapstate.StoreService {
    67  	return o.newStore(devBE)
    68  }
    69  
    70  // MockStoreNew mocks store.New as called by overlord.New.
    71  func MockStoreNew(new func(*store.Config, store.DeviceAndAuthContext) *store.Store) (restore func()) {
    72  	storeNew = new
    73  	return func() {
    74  		storeNew = store.New
    75  	}
    76  }
    77  
    78  func MockConfigstateInit(new func(*state.State, *hookstate.HookManager) error) (restore func()) {
    79  	configstateInit = new
    80  	return func() {
    81  		configstateInit = configstate.Init
    82  	}
    83  }