github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/overlord/state/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 state
    21  
    22  import (
    23  	"time"
    24  )
    25  
    26  // MockCheckpointRetryDelay changes unlockCheckpointRetryInterval and unlockCheckpointRetryMaxTime.
    27  func MockCheckpointRetryDelay(retryInterval, retryMaxTime time.Duration) (restore func()) {
    28  	oldInterval := unlockCheckpointRetryInterval
    29  	oldMaxTime := unlockCheckpointRetryMaxTime
    30  	unlockCheckpointRetryInterval = retryInterval
    31  	unlockCheckpointRetryMaxTime = retryMaxTime
    32  	return func() {
    33  		unlockCheckpointRetryInterval = oldInterval
    34  		unlockCheckpointRetryMaxTime = oldMaxTime
    35  	}
    36  }
    37  
    38  func MockChangeTimes(chg *Change, spawnTime, readyTime time.Time) {
    39  	chg.spawnTime = spawnTime
    40  	chg.readyTime = readyTime
    41  }
    42  
    43  func MockTaskTimes(t *Task, spawnTime, readyTime time.Time) {
    44  	t.spawnTime = spawnTime
    45  	t.readyTime = readyTime
    46  }
    47  
    48  func (s *State) AddWarning(message string, lastAdded, lastShown time.Time, expireAfter, repeatAfter time.Duration) {
    49  	s.addWarning(Warning{
    50  		message:     message,
    51  		lastShown:   lastShown,
    52  		expireAfter: expireAfter,
    53  		repeatAfter: repeatAfter,
    54  	}, lastAdded)
    55  }
    56  
    57  func (w Warning) LastAdded() time.Time {
    58  	return w.lastAdded
    59  }
    60  
    61  func (t *Task) AccumulateDoingTime(duration time.Duration) {
    62  	t.accumulateDoingTime(duration)
    63  }
    64  
    65  func (t *Task) AccumulateUndoingTime(duration time.Duration) {
    66  	t.accumulateUndoingTime(duration)
    67  }
    68  
    69  var (
    70  	ErrNoWarningMessage     = errNoWarningMessage
    71  	ErrBadWarningMessage    = errBadWarningMessage
    72  	ErrNoWarningFirstAdded  = errNoWarningFirstAdded
    73  	ErrNoWarningExpireAfter = errNoWarningExpireAfter
    74  	ErrNoWarningRepeatAfter = errNoWarningRepeatAfter
    75  )