github.com/chipaca/snappy@v0.0.0-20210104084008-1f06296fe8ad/gadget/install/export_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 install
    21  
    22  import (
    23  	"time"
    24  
    25  	"github.com/snapcore/snapd/gadget"
    26  )
    27  
    28  var (
    29  	MakeFilesystem  = makeFilesystem
    30  	WriteContent    = writeContent
    31  	MountFilesystem = mountFilesystem
    32  
    33  	CreateMissingPartitions = createMissingPartitions
    34  	BuildPartitionList      = buildPartitionList
    35  	RemoveCreatedPartitions = removeCreatedPartitions
    36  	EnsureNodesExist        = ensureNodesExist
    37  
    38  	CreatedDuringInstall = createdDuringInstall
    39  )
    40  
    41  func MockContentMountpoint(new string) (restore func()) {
    42  	old := contentMountpoint
    43  	contentMountpoint = new
    44  	return func() {
    45  		contentMountpoint = old
    46  	}
    47  }
    48  
    49  func MockSysMount(f func(source, target, fstype string, flags uintptr, data string) error) (restore func()) {
    50  	old := sysMount
    51  	sysMount = f
    52  	return func() {
    53  		sysMount = old
    54  	}
    55  }
    56  
    57  func MockSysUnmount(f func(target string, flags int) error) (restore func()) {
    58  	old := sysUnmount
    59  	sysUnmount = f
    60  	return func() {
    61  		sysUnmount = old
    62  	}
    63  }
    64  
    65  func MockEnsureNodesExist(f func(dss []gadget.OnDiskStructure, timeout time.Duration) error) (restore func()) {
    66  	old := ensureNodesExist
    67  	ensureNodesExist = f
    68  	return func() {
    69  		ensureNodesExist = old
    70  	}
    71  }