Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asserts: add (optional) kernel-track to model assertion #5401

Merged
merged 2 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions asserts/device_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (mod *Model) Kernel() string {
return mod.HeaderString("kernel")
}

// KernelTrack returns the kernel track the model uses.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want also a call to checkOptionalString(assert.headers, "kernel-track") in assembleModel

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedronis fixed and pushed, please have a look

func (mod *Model) KernelTrack() string {
return mod.HeaderString("kernel-track")
}

// Base returns the base snap the model uses.
func (mod *Model) Base() string {
return mod.HeaderString("base")
Expand Down
17 changes: 17 additions & 0 deletions asserts/device_asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
"gadget: brand-gadget\n" +
"base: core18\n" +
"kernel: baz-linux\n" +
"kernel-track: 4.15\n" +
"store: brand-store\n" +
sysUserAuths +
reqSnaps +
Expand Down Expand Up @@ -102,6 +103,7 @@ func (mods *modelSuite) TestDecodeOK(c *C) {
c.Check(model.Architecture(), Equals, "amd64")
c.Check(model.Gadget(), Equals, "brand-gadget")
c.Check(model.Kernel(), Equals, "baz-linux")
c.Check(model.KernelTrack(), Equals, "4.15")
c.Check(model.Base(), Equals, "core18")
c.Check(model.Store(), Equals, "brand-store")
c.Check(model.RequiredSnaps(), DeepEquals, []string{"foo", "bar"})
Expand All @@ -123,6 +125,21 @@ func (mods *modelSuite) TestDecodeStoreIsOptional(c *C) {
c.Check(model.Store(), Equals, "")
}

func (mods *modelSuite) TestDecodeKernelTrackIsOptional(c *C) {
withTimestamp := strings.Replace(modelExample, "TSLINE", mods.tsLine, 1)
encoded := strings.Replace(withTimestamp, "kernel-track: 4.15\n", "kernel-track: \n", 1)
a, err := asserts.Decode([]byte(encoded))
c.Assert(err, IsNil)
model := a.(*asserts.Model)
c.Check(model.KernelTrack(), Equals, "")

encoded = strings.Replace(withTimestamp, "kernel-track: 4.15\n", "", 1)
a, err = asserts.Decode([]byte(encoded))
c.Assert(err, IsNil)
model = a.(*asserts.Model)
c.Check(model.KernelTrack(), Equals, "")
}

func (mods *modelSuite) TestDecodeBaseIsOptional(c *C) {
withTimestamp := strings.Replace(modelExample, "TSLINE", mods.tsLine, 1)
encoded := strings.Replace(withTimestamp, "base: core18\n", "base: \n", 1)
Expand Down