gitee.com/mysnapcore/mysnapd@v0.1.0/daemon/export_api_general_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 daemon
    21  
    22  import (
    23  	"time"
    24  
    25  	"gitee.com/mysnapcore/mysnapd/overlord/state"
    26  )
    27  
    28  func MockBuildID(mock string) (restore func()) {
    29  	old := buildID
    30  	buildID = mock
    31  	return func() {
    32  		buildID = old
    33  	}
    34  }
    35  
    36  func MockSystemdVirt(newVirt string) (restore func()) {
    37  	oldVirt := systemdVirt
    38  	systemdVirt = newVirt
    39  	return func() { systemdVirt = oldVirt }
    40  }
    41  
    42  func MockWarningsAccessors(okay func(*state.State, time.Time) int, all func(*state.State) []*state.Warning, pending func(*state.State) ([]*state.Warning, time.Time)) (restore func()) {
    43  	oldOK := stateOkayWarnings
    44  	oldAll := stateAllWarnings
    45  	oldPending := statePendingWarnings
    46  	stateOkayWarnings = okay
    47  	stateAllWarnings = all
    48  	statePendingWarnings = pending
    49  	return func() {
    50  		stateOkayWarnings = oldOK
    51  		stateAllWarnings = oldAll
    52  		statePendingWarnings = oldPending
    53  	}
    54  }
    55  
    56  type (
    57  	ChangeInfo = changeInfo
    58  )