本文整理汇总了Golang中github.com/snapcore/snapd/snap/snaptest.MakeTestSnapWithFiles函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeTestSnapWithFiles函数的具体用法?Golang MakeTestSnapWithFiles怎么用?Golang MakeTestSnapWithFiles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeTestSnapWithFiles函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDoUndoMountSnap
func (s *mountSnapSuite) TestDoUndoMountSnap(c *C) {
v1 := "name: core\nversion: 1.0\n"
testSnap := snaptest.MakeTestSnapWithFiles(c, v1, nil)
s.state.Lock()
defer s.state.Unlock()
si1 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(1),
}
si2 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(2),
}
snapstate.Set(s.state, "core", &snapstate.SnapState{
Sequence: []*snap.SideInfo{si1},
Current: si1.Revision,
SnapType: "os",
})
t := s.state.NewTask("mount-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: si2,
SnapPath: testSnap,
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
// ensure undo was called the right way
c.Check(s.fakeBackend.ops, DeepEquals, fakeOps{
{
op: "current",
old: "/snap/core/1",
},
{
op: "setup-snap",
name: testSnap,
revno: snap.R(2),
},
{
op: "undo-setup-snap",
name: "/snap/core/2",
stype: "os",
},
})
}
示例2: TestDownloadUnpackGadget
func (s *imageSuite) TestDownloadUnpackGadget(c *C) {
files := [][]string{
{"subdir/canary.txt", "I'm a canary"},
}
s.downloadedSnaps["pc"] = snaptest.MakeTestSnapWithFiles(c, packageGadget, files)
s.storeSnapInfo["pc"] = infoFromSnapYaml(c, packageGadget, snap.R(99))
gadgetUnpackDir := filepath.Join(c.MkDir(), "gadget-unpack-dir")
opts := &image.Options{
GadgetUnpackDir: gadgetUnpackDir,
}
local, err := image.LocalSnaps(opts)
c.Assert(err, IsNil)
err = image.DownloadUnpackGadget(s, s.model, opts, local)
c.Assert(err, IsNil)
// verify the right data got unpacked
for _, t := range []struct{ file, content string }{
{"meta/snap.yaml", packageGadget},
{files[0][0], files[0][1]},
} {
fn := filepath.Join(gadgetUnpackDir, t.file)
content, err := ioutil.ReadFile(fn)
c.Assert(err, IsNil)
c.Check(content, DeepEquals, []byte(t.content))
}
}
示例3: TestExtractKernelAssetsNoUnpacksKernelForGrub
func (s *kernelOSSuite) TestExtractKernelAssetsNoUnpacksKernelForGrub(c *C) {
// pretend to be a grub system
mockGrub := boottest.NewMockBootloader("grub", c.MkDir())
partition.ForceBootloader(mockGrub)
files := [][]string{
{"kernel.img", "I'm a kernel"},
{"initrd.img", "...and I'm an initrd"},
{"meta/kernel.yaml", "version: 4.2"},
}
si := &snap.SideInfo{
RealName: "ubuntu-kernel",
Revision: snap.R(42),
}
fn := snaptest.MakeTestSnapWithFiles(c, packageKernel, files)
snapf, err := snap.Open(fn)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, si)
c.Assert(err, IsNil)
err = boot.ExtractKernelAssets(info, snapf)
c.Assert(err, IsNil)
// kernel is *not* here
kernimg := filepath.Join(mockGrub.Dir(), "ubuntu-kernel_42.snap", "kernel.img")
c.Assert(osutil.FileExists(kernimg), Equals, false)
}
示例4: makeTestSnap
func (s *storeTestSuite) makeTestSnap(c *C, snapYamlContent string) string {
fn := snaptest.MakeTestSnapWithFiles(c, snapYamlContent, nil)
dst := filepath.Join(s.store.blobDir, filepath.Base(fn))
err := osutil.CopyFile(fn, dst, 0)
c.Assert(err, IsNil)
return dst
}
示例5: TestReadInfoFromSnapFileCatchesInvalidImplicitHook
func (s *infoSuite) TestReadInfoFromSnapFileCatchesInvalidImplicitHook(c *C) {
yaml := `name: foo
version: 1.0`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, emptyHooks("123abc"))
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
_, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, ErrorMatches, ".*invalid hook name.*")
}
示例6: setupSnaps
func (s *imageSuite) setupSnaps(c *C, gadgetUnpackDir string) {
err := os.MkdirAll(gadgetUnpackDir, 0755)
c.Assert(err, IsNil)
err = ioutil.WriteFile(filepath.Join(gadgetUnpackDir, "grub.conf"), nil, 0644)
c.Assert(err, IsNil)
s.downloadedSnaps["pc"] = snaptest.MakeTestSnapWithFiles(c, packageGadget, [][]string{{"grub.cfg", "I'm a grub.cfg"}})
s.storeSnapInfo["pc"] = infoFromSnapYaml(c, packageGadget, snap.R(1))
s.addSystemSnapAssertions(c, "pc")
s.downloadedSnaps["pc-kernel"] = snaptest.MakeTestSnapWithFiles(c, packageKernel, nil)
s.storeSnapInfo["pc-kernel"] = infoFromSnapYaml(c, packageKernel, snap.R(2))
s.addSystemSnapAssertions(c, "pc-kernel")
s.downloadedSnaps["core"] = snaptest.MakeTestSnapWithFiles(c, packageCore, nil)
s.storeSnapInfo["core"] = infoFromSnapYaml(c, packageCore, snap.R(3))
s.addSystemSnapAssertions(c, "core")
s.downloadedSnaps["required-snap1"] = snaptest.MakeTestSnapWithFiles(c, requiredSnap1, nil)
s.storeSnapInfo["required-snap1"] = infoFromSnapYaml(c, requiredSnap1, snap.R(3))
s.addSystemSnapAssertions(c, "required-snap1")
}
示例7: TestSetupUndoIdempotent
func (s *setupSuite) TestSetupUndoIdempotent(c *C) {
// make sure that a retry wouldn't stumble on partial work
// use a kernel because that does and need to do strictly more
// this cannot check systemd own behavior though around mounts!
bootloader := boottest.NewMockBootloader("mock", c.MkDir())
partition.ForceBootloader(bootloader)
// we don't get real mounting
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
defer os.Unsetenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS")
testFiles := [][]string{
{"kernel.img", "kernel"},
{"initrd.img", "initrd"},
{"modules/4.4.0-14-generic/foo.ko", "a module"},
{"firmware/bar.bin", "some firmware"},
{"meta/kernel.yaml", "version: 4.2"},
}
snapPath := snaptest.MakeTestSnapWithFiles(c, `name: kernel
version: 1.0
type: kernel
`, testFiles)
si := snap.SideInfo{
RealName: "kernel",
Revision: snap.R(140),
}
err := s.be.SetupSnap(snapPath, &si, &s.nullProgress)
c.Assert(err, IsNil)
minInfo := snap.MinimalPlaceInfo("kernel", snap.R(140))
err = s.be.UndoSetupSnap(minInfo, "kernel", &s.nullProgress)
c.Assert(err, IsNil)
// retry run
err = s.be.UndoSetupSnap(minInfo, "kernel", &s.nullProgress)
c.Assert(err, IsNil)
// sanity checks
l, _ := filepath.Glob(filepath.Join(dirs.SnapServicesDir, "*.mount"))
c.Assert(l, HasLen, 0)
c.Assert(osutil.FileExists(minInfo.MountDir()), Equals, false)
c.Assert(osutil.FileExists(minInfo.MountFile()), Equals, false)
l, _ = filepath.Glob(filepath.Join(bootloader.Dir(), "*"))
c.Assert(l, HasLen, 0)
}
示例8: TestReadInfoFromSnapFileMissingEpoch
func (s *infoSuite) TestReadInfoFromSnapFileMissingEpoch(c *C) {
yaml := `name: foo
version: 1.0
type: app`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "foo")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(0))
c.Check(info.Epoch, Equals, "0") // Defaults to 0
}
示例9: TestExtractKernelAssetsAndRemove
func (s *kernelOSSuite) TestExtractKernelAssetsAndRemove(c *C) {
files := [][]string{
{"kernel.img", "I'm a kernel"},
{"initrd.img", "...and I'm an initrd"},
{"dtbs/foo.dtb", "g'day, I'm foo.dtb"},
{"dtbs/bar.dtb", "hello, I'm bar.dtb"},
// must be last
{"meta/kernel.yaml", "version: 4.2"},
}
si := &snap.SideInfo{
RealName: "ubuntu-kernel",
Revision: snap.R(42),
}
fn := snaptest.MakeTestSnapWithFiles(c, packageKernel, files)
snapf, err := snap.Open(fn)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, si)
c.Assert(err, IsNil)
err = boot.ExtractKernelAssets(info, snapf)
c.Assert(err, IsNil)
// this is where the kernel/initrd is unpacked
bootdir := s.bootloader.Dir()
kernelAssetsDir := filepath.Join(bootdir, "ubuntu-kernel_42.snap")
for _, def := range files {
if def[0] == "meta/kernel.yaml" {
break
}
fullFn := filepath.Join(kernelAssetsDir, def[0])
content, err := ioutil.ReadFile(fullFn)
c.Assert(err, IsNil)
c.Assert(string(content), Equals, def[1])
}
// remove
err = boot.RemoveKernelAssets(info)
c.Assert(err, IsNil)
c.Check(osutil.FileExists(kernelAssetsDir), Equals, false)
}
示例10: checkInstalledSnapAndSnapFile
func (s *infoSuite) checkInstalledSnapAndSnapFile(c *C, yaml string, contents string, hooks []string, checker func(c *C, info *snap.Info)) {
// First check installed snap
sideInfo := &snap.SideInfo{Revision: snap.R(42)}
info0 := snaptest.MockSnap(c, yaml, contents, sideInfo)
snaptest.PopulateDir(info0.MountDir(), emptyHooks(hooks...))
info, err := snap.ReadInfo(info0.Name(), sideInfo)
c.Check(err, IsNil)
checker(c, info)
// Now check snap file
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, emptyHooks(hooks...))
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err = snap.ReadInfoFromSnapFile(snapf, nil)
c.Check(err, IsNil)
checker(c, info)
}
示例11: TestReadInfoFromSnapFileWithSideInfo
func (s *infoSuite) TestReadInfoFromSnapFileWithSideInfo(c *C) {
yaml := `name: foo
version: 1.0
type: app`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, &snap.SideInfo{
RealName: "baz",
Revision: snap.R(42),
})
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "baz")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(42))
}
示例12: TestReadInfoFromSnapFile
func (s *infoSuite) TestReadInfoFromSnapFile(c *C) {
yaml := `name: foo
version: 1.0
type: app
epoch: 1*
confinement: devmode`
snapPath := snaptest.MakeTestSnapWithFiles(c, yaml, nil)
snapf, err := snap.Open(snapPath)
c.Assert(err, IsNil)
info, err := snap.ReadInfoFromSnapFile(snapf, nil)
c.Assert(err, IsNil)
c.Check(info.Name(), Equals, "foo")
c.Check(info.Version, Equals, "1.0")
c.Check(info.Type, Equals, snap.TypeApp)
c.Check(info.Revision, Equals, snap.R(0))
c.Check(info.Epoch, Equals, "1*")
c.Check(info.Confinement, Equals, snap.DevModeConfinement)
}
示例13: TestInstallKernelSnapUpdatesBootloader
func (ms *mgrsSuite) TestInstallKernelSnapUpdatesBootloader(c *C) {
bootloader := boottest.NewMockBootloader("mock", c.MkDir())
partition.ForceBootloader(bootloader)
defer partition.ForceBootloader(nil)
restore := release.MockOnClassic(false)
defer restore()
const packageKernel = `
name: krnl
version: 4.0-1
type: kernel`
files := [][]string{
{"kernel.img", "I'm a kernel"},
{"initrd.img", "...and I'm an initrd"},
{"meta/kernel.yaml", "version: 4.2"},
}
snapPath := snaptest.MakeTestSnapWithFiles(c, packageKernel, files)
st := ms.o.State()
st.Lock()
defer st.Unlock()
ts, err := snapstate.InstallPath(st, &snap.SideInfo{RealName: "krnl"}, snapPath, "", 0)
c.Assert(err, IsNil)
chg := st.NewChange("install-snap", "...")
chg.AddAll(ts)
st.Unlock()
err = ms.o.Settle()
st.Lock()
c.Assert(err, IsNil)
c.Assert(chg.Status(), Equals, state.DoneStatus, Commentf("install-snap change failed with: %v", chg.Err()))
c.Assert(bootloader.BootVars, DeepEquals, map[string]string{
"snap_try_kernel": "krnl_x1.snap",
"snap_mode": "try",
})
}
示例14: TestSetupDoUndoKernelUboot
func (s *setupSuite) TestSetupDoUndoKernelUboot(c *C) {
bootloader := boottest.NewMockBootloader("mock", c.MkDir())
partition.ForceBootloader(bootloader)
// we don't get real mounting
os.Setenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS", "1")
defer os.Unsetenv("SNAPPY_SQUASHFS_UNPACK_FOR_TESTS")
testFiles := [][]string{
{"kernel.img", "kernel"},
{"initrd.img", "initrd"},
{"modules/4.4.0-14-generic/foo.ko", "a module"},
{"firmware/bar.bin", "some firmware"},
{"meta/kernel.yaml", "version: 4.2"},
}
snapPath := snaptest.MakeTestSnapWithFiles(c, `name: kernel
version: 1.0
type: kernel
`, testFiles)
si := snap.SideInfo{
RealName: "kernel",
Revision: snap.R(140),
}
err := s.be.SetupSnap(snapPath, &si, &s.nullProgress)
c.Assert(err, IsNil)
l, _ := filepath.Glob(filepath.Join(bootloader.Dir(), "*"))
c.Assert(l, HasLen, 1)
minInfo := snap.MinimalPlaceInfo("kernel", snap.R(140))
// undo deletes the kernel assets again
err = s.be.UndoSetupSnap(minInfo, "kernel", &s.nullProgress)
c.Assert(err, IsNil)
l, _ = filepath.Glob(filepath.Join(bootloader.Dir(), "*"))
c.Assert(l, HasLen, 0)
}
示例15: TestDoMountSnapRemovesSnaps
func (s *mountSnapSuite) TestDoMountSnapRemovesSnaps(c *C) {
v1 := "name: mock\nversion: 1.0\n"
testSnap := snaptest.MakeTestSnapWithFiles(c, v1, nil)
s.state.Lock()
t := s.state.NewTask("mount-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(33),
},
SnapPath: testSnap,
DownloadInfo: &snap.DownloadInfo{DownloadURL: "https://some"},
})
s.state.NewChange("dummy", "...").AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
c.Assert(osutil.FileExists(testSnap), Equals, false)
}