Skip to content

Commit

Permalink
o/snapstate: test tasks created when installing snap+comps from file
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewphelpsj committed Jun 26, 2024
1 parent e3ab93a commit 9fb4269
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
6 changes: 5 additions & 1 deletion overlord/snapstate/snapstate_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func expectedDoInstallTasks(typ snap.Type, opts, discards int, startTasks []stri

afterLinkSnap := make([]string, 0, len(components))
for range components {
compTasks := expectedComponentInstallTasks(compOptSkipSecurity)
compOpts := compOptSkipSecurity
if opts&localSnap != 0 {
compOpts |= compOptIsLocal
}
compTasks := expectedComponentInstallTasks(compOpts)
for i, t := range compTasks {
if t == "link-component" {
afterLinkSnap = append(afterLinkSnap, compTasks[i:]...)
Expand Down
51 changes: 51 additions & 0 deletions overlord/snapstate/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/snapcore/snapd/overlord/snapstate"
"github.com/snapcore/snapd/snap"
"github.com/snapcore/snapd/snap/naming"
"github.com/snapcore/snapd/snap/snaptest"
"github.com/snapcore/snapd/store"
. "gopkg.in/check.v1"
)
Expand Down Expand Up @@ -175,3 +177,52 @@ func (s *TargetTestSuite) TestInstallWithComponentsMissingInInfo(c *C) {
_, _, err := snapstate.InstallOne(context.Background(), s.state, goal, snapstate.Options{})
c.Assert(err, ErrorMatches, fmt.Sprintf(`.*"%s" is not a component for snap "%s"`, compName, snapName))
}

func (s *TargetTestSuite) TestInstallWithComponentsFromPath(c *C) {
s.state.Lock()
defer s.state.Unlock()

const (
snapName = "test-snap"
snapID = "test-snap-id"
compName = "test-component"
snapYaml = `name: test-snap
version: 1.0
components:
test-component:
type: test
kernel-modules-component:
type: kernel-modules
`
componentYaml = `component: test-snap+test-component
type: test
version: 1.0
`
)

snapRevision := snap.R(2)
si := &snap.SideInfo{
RealName: snapName,
SnapID: snapID,
Revision: snapRevision,
}
snapPath := makeTestSnap(c, snapYaml)

csi := &snap.ComponentSideInfo{
Component: naming.NewComponentRef(snapName, compName),
Revision: snap.R(3),
}
components := map[*snap.ComponentSideInfo]string{
csi: snaptest.MakeTestComponent(c, componentYaml),
}

goal := snapstate.PathInstallGoal(snapName, snapPath, si, components, snapstate.RevisionOptions{})

info, ts, err := snapstate.InstallOne(context.Background(), s.state, goal, snapstate.Options{})
c.Assert(err, IsNil)

c.Check(info.InstanceName(), Equals, snapName)
c.Check(info.Components[compName].Name, Equals, compName)

verifyInstallTasksWithComponents(c, snap.TypeApp, localSnap, 0, []string{compName}, ts)
}

0 comments on commit 9fb4269

Please sign in to comment.