Skip to content

Commit

Permalink
Added command line option for extra assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-medici committed Jan 17, 2025
1 parent e95ef72 commit 1d3f1ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/snap/cmd_prepare_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type cmdPrepareImage struct {
ExtraSnaps []string `long:"extra-snaps" hidden:"yes"` // DEPRECATED
RevisionsFile string `long:"revisions"`
WriteRevisionsFile string `long:"write-revisions" optional:"true" optional-value:"./seed.manifest"`

// Filenames for injected assertions
ExtraAssertions []string `long:"assert" value-name:"<filename>"`
}

func init() {
Expand Down Expand Up @@ -100,6 +103,8 @@ For preparing classic images it supports a --classic mode`),
"channel": i18n.G("The channel to use"),
// TRANSLATORS: This should not start with a lowercase letter.
"customize": i18n.G("Image customizations specified as JSON file."),
// TRANSLATORS: This should not start with a lowercase letter.
"assert": i18n.G("Include the assertion from the local file"),
}, []argDesc{
{
// TRANSLATORS: This needs to begin with < and end with >
Expand All @@ -125,12 +130,13 @@ func (x *cmdPrepareImage) Execute(args []string) error {
snap.SanitizePlugsSlots = builtin.SanitizePlugsSlots

opts := &image.Options{
Snaps: x.ExtraSnaps,
Components: x.Components,
ModelFile: x.Positional.ModelAssertionFn,
Channel: x.Channel,
Architecture: x.Architecture,
SeedManifestPath: x.WriteRevisionsFile,
Snaps: x.ExtraSnaps,
Components: x.Components,
ModelFile: x.Positional.ModelAssertionFn,
Channel: x.Channel,
Architecture: x.Architecture,
SeedManifestPath: x.WriteRevisionsFile,
AdditionalAssertionsFiles: x.ExtraAssertions,
}

if x.RevisionsFile != "" {
Expand Down
20 changes: 20 additions & 0 deletions cmd/snap/cmd_prepare_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,23 @@ func (s *SnapPrepareImageSuite) TestPrepareImageWriteRevisions(c *C) {
SeedManifestPath: "/tmp/seed.manifest",
})
}

func (s *SnapPrepareImageSuite) TestPrepareImageCoreExtraAssertions(c *C) {
var opts *image.Options
prep := func(o *image.Options) error {
opts = o
return nil
}
r := cmdsnap.MockImagePrepare(prep)
defer r()

rest, err := cmdsnap.Parser(cmdsnap.Client()).ParseArgs([]string{"prepare-image", "model", "prepare-dir", "--assert", "extra1", "--assert", "extra2"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})

c.Check(opts, DeepEquals, &image.Options{
ModelFile: "model",
PrepareDir: "prepare-dir",
AdditionalAssertionsFiles: []string{"extra1", "extra2"},
})
}

0 comments on commit 1d3f1ca

Please sign in to comment.