github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/errtracker/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 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 errtracker
    21  
    22  import (
    23  	"time"
    24  )
    25  
    26  func MockCrashDbURL(url string) (restorer func()) {
    27  	old := CrashDbURLBase
    28  	CrashDbURLBase = url
    29  	return func() {
    30  		CrashDbURLBase = old
    31  	}
    32  }
    33  
    34  func MockMachineIDPaths(paths []string) (restorer func()) {
    35  	old := machineIDs
    36  	machineIDs = paths
    37  	return func() {
    38  		machineIDs = old
    39  	}
    40  }
    41  
    42  func MockHostSnapd(path string) (restorer func()) {
    43  	old := mockedHostSnapd
    44  	mockedHostSnapd = path
    45  	return func() {
    46  		mockedHostSnapd = old
    47  	}
    48  }
    49  
    50  func MockCoreSnapd(path string) (restorer func()) {
    51  	old := mockedCoreSnapd
    52  	mockedCoreSnapd = path
    53  	return func() {
    54  		mockedCoreSnapd = old
    55  	}
    56  }
    57  
    58  func MockTimeNow(f func() time.Time) (restorer func()) {
    59  	old := timeNow
    60  	timeNow = f
    61  	return func() {
    62  		timeNow = old
    63  	}
    64  }
    65  
    66  func MockReExec(f func() string) (restorer func()) {
    67  	oldDidSnapdReExec := didSnapdReExec
    68  	didSnapdReExec = f
    69  	return func() {
    70  		didSnapdReExec = oldDidSnapdReExec
    71  	}
    72  }
    73  
    74  func MockOsGetenv(f func(string) string) (restorer func()) {
    75  	old := osGetenv
    76  	osGetenv = f
    77  	return func() {
    78  		osGetenv = old
    79  	}
    80  }
    81  
    82  func MockProcCpuinfo(filename string) (restorer func()) {
    83  	old := procCpuinfo
    84  	procCpuinfo = filename
    85  	return func() {
    86  		procCpuinfo = old
    87  	}
    88  }
    89  
    90  func MockProcSelfExe(filename string) (restorer func()) {
    91  	old := procSelfExe
    92  	procSelfExe = filename
    93  	return func() {
    94  		procSelfExe = old
    95  	}
    96  }
    97  
    98  func MockProcSelfCwd(filename string) (restorer func()) {
    99  	old := procSelfCwd
   100  	procSelfCwd = filename
   101  	return func() {
   102  		procSelfCwd = old
   103  	}
   104  }
   105  
   106  func MockProcSelfCmdline(filename string) (restorer func()) {
   107  	old := procSelfCmdline
   108  	procSelfCmdline = filename
   109  	return func() {
   110  		procSelfCmdline = old
   111  	}
   112  }
   113  
   114  var (
   115  	ProcExe            = procExe
   116  	ProcCwd            = procCwd
   117  	ProcCmdline        = procCmdline
   118  	JournalError       = journalError
   119  	ProcCpuinfoMinimal = procCpuinfoMinimal
   120  	Environ            = environ
   121  	NewReportsDB       = newReportsDB
   122  )
   123  
   124  func SetReportDBCleanupTime(db *reportsDB, d time.Duration) {
   125  	db.cleanupTime = d
   126  }