github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/cmd/snap-preseed/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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 main
    21  
    22  import (
    23  	"github.com/snapcore/snapd/seed"
    24  )
    25  
    26  var (
    27  	Run                      = run
    28  	SystemSnapFromSeed       = systemSnapFromSeed
    29  	ChooseTargetSnapdVersion = chooseTargetSnapdVersion
    30  )
    31  
    32  func MockOsGetuid(f func() int) (restore func()) {
    33  	oldOsGetuid := osGetuid
    34  	osGetuid = f
    35  	return func() { osGetuid = oldOsGetuid }
    36  }
    37  
    38  func MockSyscallChroot(f func(string) error) (restore func()) {
    39  	oldSyscallChroot := syscallChroot
    40  	syscallChroot = f
    41  	return func() { syscallChroot = oldSyscallChroot }
    42  }
    43  
    44  func MockSnapdMountPath(path string) (restore func()) {
    45  	oldMountPath := snapdMountPath
    46  	snapdMountPath = path
    47  	return func() { snapdMountPath = oldMountPath }
    48  }
    49  
    50  func MockSystemSnapFromSeed(f func(rootDir string) (string, error)) (restore func()) {
    51  	oldSystemSnapFromSeed := systemSnapFromSeed
    52  	systemSnapFromSeed = f
    53  	return func() { systemSnapFromSeed = oldSystemSnapFromSeed }
    54  }
    55  
    56  func MockSeedOpen(f func(rootDir, label string) (seed.Seed, error)) (restore func()) {
    57  	oldSeedOpen := seedOpen
    58  	seedOpen = f
    59  	return func() {
    60  		seedOpen = oldSeedOpen
    61  	}
    62  }
    63  
    64  func SnapdPathAndVersion(targetSnapd *targetSnapdInfo) (string, string) {
    65  	return targetSnapd.path, targetSnapd.version
    66  }