gitee.com/mysnapcore/mysnapd@v0.1.0/image/export_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-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 image
    21  
    22  import (
    23  	"gitee.com/mysnapcore/mysnapd/asserts"
    24  	"gitee.com/mysnapcore/mysnapd/gadget"
    25  	"gitee.com/mysnapcore/mysnapd/store/tooling"
    26  	"gitee.com/mysnapcore/mysnapd/testutil"
    27  )
    28  
    29  var (
    30  	DecodeModelAssertion = decodeModelAssertion
    31  	MakeLabel            = makeLabel
    32  	SetupSeed            = setupSeed
    33  	InstallCloudConfig   = installCloudConfig
    34  )
    35  
    36  var (
    37  	WriteResolvedContent = writeResolvedContent
    38  )
    39  
    40  func MockWriteResolvedContent(f func(prepareImageDir string, info *gadget.Info, gadgetRoot, kernelRoot string) error) (restore func()) {
    41  	oldWriteResolvedContent := writeResolvedContent
    42  	writeResolvedContent = f
    43  	return func() {
    44  		writeResolvedContent = oldWriteResolvedContent
    45  	}
    46  }
    47  
    48  func MockNewToolingStoreFromModel(f func(model *asserts.Model, fallbackArchitecture string) (*tooling.ToolingStore, error)) (restore func()) {
    49  	old := newToolingStoreFromModel
    50  	newToolingStoreFromModel = f
    51  	return func() {
    52  		newToolingStoreFromModel = old
    53  	}
    54  }
    55  
    56  func MockPreseedCore20(f func(dir string, key, aaDir string) error) (restore func()) {
    57  	r := testutil.Backup(&preseedCore20)
    58  	preseedCore20 = f
    59  	return r
    60  }
    61  
    62  func MockSetupSeed(f func(tsto *tooling.ToolingStore, model *asserts.Model, opts *Options) error) (restore func()) {
    63  	r := testutil.Backup(&setupSeed)
    64  	setupSeed = f
    65  	return r
    66  }