gitee.com/mysnapcore/mysnapd@v0.1.0/cmd/snap-exec/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2014-2015 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  	"syscall"
    24  
    25  	"gitee.com/mysnapcore/mysnapd/testutil"
    26  )
    27  
    28  var (
    29  	ExpandEnvCmdArgs = expandEnvCmdArgs
    30  	FindCommand      = findCommand
    31  	ParseArgs        = parseArgs
    32  	Run              = run
    33  	ExecApp          = execApp
    34  	ExecHook         = execHook
    35  )
    36  
    37  func MockSyscallExec(f func(argv0 string, argv []string, envv []string) (err error)) func() {
    38  	origSyscallExec := syscallExec
    39  	syscallExec = f
    40  	return func() {
    41  		syscallExec = origSyscallExec
    42  	}
    43  }
    44  
    45  func SetOptsCommand(s string) {
    46  	opts.Command = s
    47  }
    48  func GetOptsCommand() string {
    49  	return opts.Command
    50  }
    51  
    52  func SetOptsHook(s string) {
    53  	opts.Hook = s
    54  }
    55  func GetOptsHook() string {
    56  	return opts.Hook
    57  }
    58  
    59  // MockOsReadlink is for use in tests
    60  func MockOsReadlink(f func(string) (string, error)) func() {
    61  	realOsReadlink := osReadlink
    62  	osReadlink = f
    63  	return func() {
    64  		osReadlink = realOsReadlink
    65  	}
    66  }
    67  
    68  func MockSyscallStat(f func(string, *syscall.Stat_t) (err error)) func() {
    69  	r := testutil.Backup(&syscallStat)
    70  	syscallStat = f
    71  	return r
    72  }