File: fde.go

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (75 lines) | stat: -rw-r--r-- 1,996 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package boottest

import (
	"fmt"
	"os"
	"path/filepath"

	. "gopkg.in/check.v1"

	"github.com/snapcore/snapd/dirs"
	"github.com/snapcore/snapd/seed"
	"github.com/snapcore/snapd/snap"
	"github.com/snapcore/snapd/snap/snaptest"
)

// MockAssetsCache mocks the listed assets in the boot assets cache by creating
// an empty file for each.
func MockAssetsCache(c *C, rootdir, bootloaderName string, cachedAssets []string) {
	p := filepath.Join(dirs.SnapBootAssetsDirUnder(rootdir), bootloaderName)
	err := os.MkdirAll(p, 0755)
	c.Assert(err, IsNil)
	for _, cachedAsset := range cachedAssets {
		err = os.WriteFile(filepath.Join(p, cachedAsset), nil, 0644)
		c.Assert(err, IsNil)
	}
}

// MockNamedKernelSeedSnap creates a seed snap representation for a kernel snap
// with a given name and revision.
func MockNamedKernelSeedSnap(rev snap.Revision, name string) *seed.Snap {
	revAsString := rev.String()
	if rev.Unset() {
		revAsString = "unset"
	}
	return &seed.Snap{
		Path: fmt.Sprintf("/var/lib/snapd/seed/snaps/%v_%v.snap", name, revAsString),
		SideInfo: &snap.SideInfo{
			RealName: name,
			Revision: rev,
		},
		EssentialType: snap.TypeKernel,
	}
}

// MockGadgetSeedSnap creates a seed snap representation of a gadget snap with
// given snap.yaml and a list of files. If gadget.yaml is not provided in the
// file list, a mock one, referencing the grub bootloader, is added
// automatically.
func MockGadgetSeedSnap(c *C, snapYaml string, files [][]string) *seed.Snap {
	mockGadgetYaml := `
volumes:
  volumename:
    bootloader: grub
`

	hasGadgetYaml := false
	for _, entry := range files {
		if entry[0] == "meta/gadget.yaml" {
			hasGadgetYaml = true
		}
	}
	if !hasGadgetYaml {
		files = append(files, []string{"meta/gadget.yaml", mockGadgetYaml})
	}

	gadgetSnapFile := snaptest.MakeTestSnapWithFiles(c, snapYaml, files)
	return &seed.Snap{
		Path: gadgetSnapFile,
		SideInfo: &snap.SideInfo{
			RealName: "gadget",
			Revision: snap.R(1),
		},
		EssentialType: snap.TypeGadget,
	}
}