github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/snapdtool/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017-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 snapdtool
    21  
    22  var (
    23  	DistroSupportsReExec = distroSupportsReExec
    24  	CoreSupportsReExec   = coreSupportsReExec
    25  )
    26  
    27  func MockCoreSnapdPaths(newCoreSnap, newSnapdSnap string) func() {
    28  	oldOldCore := coreSnap
    29  	oldNewCore := snapdSnap
    30  	snapdSnap = newSnapdSnap
    31  	coreSnap = newCoreSnap
    32  	return func() {
    33  		snapdSnap = oldNewCore
    34  		coreSnap = oldOldCore
    35  	}
    36  }
    37  
    38  func MockSelfExe(newSelfExe string) func() {
    39  	oldSelfExe := selfExe
    40  	selfExe = newSelfExe
    41  	return func() {
    42  		selfExe = oldSelfExe
    43  	}
    44  }
    45  
    46  func MockSyscallExec(f func(argv0 string, argv []string, envv []string) (err error)) func() {
    47  	oldSyscallExec := syscallExec
    48  	syscallExec = f
    49  	return func() {
    50  		syscallExec = oldSyscallExec
    51  	}
    52  }