From 9fb4269c684ef0701bfd7ff0ac308f50e0dc1f72 Mon Sep 17 00:00:00 2001 From: Andrew Phelps Date: Mon, 20 May 2024 15:23:38 -0400 Subject: [PATCH] o/snapstate: test tasks created when installing snap+comps from file --- overlord/snapstate/snapstate_install_test.go | 6 ++- overlord/snapstate/target_test.go | 51 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/overlord/snapstate/snapstate_install_test.go b/overlord/snapstate/snapstate_install_test.go index a18a5e21295..c6b23c0dfb2 100644 --- a/overlord/snapstate/snapstate_install_test.go +++ b/overlord/snapstate/snapstate_install_test.go @@ -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:]...) diff --git a/overlord/snapstate/target_test.go b/overlord/snapstate/target_test.go index 83be6f47f8e..3da0361e1fd 100644 --- a/overlord/snapstate/target_test.go +++ b/overlord/snapstate/target_test.go @@ -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" ) @@ -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) +}