@@ -21,7 +21,9 @@ package snapstate_test
2121
2222import (
2323 "errors"
24+ "fmt"
2425
26+ "github.com/snapcore/snapd/overlord/configstate/config"
2527 "github.com/snapcore/snapd/overlord/snapstate"
2628 "github.com/snapcore/snapd/overlord/snapstate/sequence"
2729 "github.com/snapcore/snapd/overlord/snapstate/snapstatetest"
@@ -460,3 +462,35 @@ func (s *snapmgrTestSuite) TestRemoveComponentUpdateNoConflict(c *C) {
460462 c .Assert (len (tss ), Equals , 1 )
461463 verifyComponentRemoveTasks (c , compCurrentIsDiscarded , tss [0 ])
462464}
465+
466+ func (s * snapmgrTestSuite ) TestRemoveComponentInSeedRefresh (c * C ) {
467+ const snapName = "some-snap"
468+ const compName = "mycomp"
469+ snapRev := snap .R (1 )
470+ info := createTestSnapInfoForComponent (c , snapName , snapRev , compName )
471+ ci , _ := createTestComponent (c , snapName , compName , info )
472+ s .AddCleanup (snapstate .MockReadComponentInfo (func (compMntDir string ,
473+ snapInfo * snap.Info , csi * snap.ComponentSideInfo ) (* snap.ComponentInfo , error ) {
474+ return ci , nil
475+ }))
476+
477+ s .state .Lock ()
478+ defer s .state .Unlock ()
479+ tr := config .NewTransaction (s .state )
480+ c .Assert (tr .Set ("core" , "experimental.seed-refresh" , true ), IsNil )
481+ tr .Commit ()
482+
483+ s .AddCleanup (snapstate .MockCheckComponentSeedRefreshRemove (func (st * state.State ,
484+ si * snap.Info , componentName string , dctx snapstate.DeviceContext ) error {
485+ return fmt .Errorf ("blocked by seed refresh" )
486+ }))
487+
488+ csi1 := snap .NewComponentSideInfo (naming .NewComponentRef (snapName , compName ), snap .R (1 ))
489+ cs1 := sequence .NewComponentState (csi1 , snap .StandardComponent )
490+ setStateWithComponents (s .state , snapName , snapRev , []* sequence.ComponentState {cs1 })
491+
492+ _ , err := snapstate .RemoveComponents (s .state , snapName , []string {compName },
493+ snapstate.RemoveComponentsOpts {})
494+
495+ c .Assert (err , ErrorMatches , "blocked by seed refresh" )
496+ }
0 commit comments