func (s *snapmgrTestSuite) TestAutoAliasesDeltaAll(c *C) { seen := make(map[string]bool) snapstate.AutoAliases = func(st *state.State, info *snap.Info) ([]string, error) { seen[info.Name()] = true if info.Name() == "alias-snap" { return []string{"alias1", "alias2", "alias4", "alias5"}, nil } return nil, nil } s.state.Lock() defer s.state.Unlock() snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{ Sequence: []*snap.SideInfo{ {RealName: "alias-snap", Revision: snap.R(11)}, }, Current: snap.R(11), Active: true, }) snapstate.Set(s.state, "other-snap", &snapstate.SnapState{ Sequence: []*snap.SideInfo{ {RealName: "other-snap", Revision: snap.R(2)}, }, Current: snap.R(2), Active: true, }) new, retired, err := snapstate.AutoAliasesDelta(s.state, nil) c.Assert(err, IsNil) c.Check(new, DeepEquals, map[string][]string{ "alias-snap": {"alias1", "alias2", "alias4", "alias5"}, }) c.Check(retired, HasLen, 0) c.Check(seen, DeepEquals, map[string]bool{ "alias-snap": true, "other-snap": true, }) }
func (s *snapmgrTestSuite) TestAutoAliasesDelta(c *C) { snapstate.AutoAliases = func(st *state.State, info *snap.Info) ([]string, error) { c.Check(info.Name(), Equals, "alias-snap") return []string{"alias1", "alias2", "alias4", "alias5"}, nil } s.state.Lock() defer s.state.Unlock() snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{ Sequence: []*snap.SideInfo{ {RealName: "alias-snap", Revision: snap.R(11)}, }, Current: snap.R(11), Active: true, }) s.state.Set("aliases", map[string]map[string]string{ "alias-snap": { "alias1": "enabled", "alias2": "disabled", "alias3": "auto", }, }) new, retired, err := snapstate.AutoAliasesDelta(s.state, []string{"alias-snap"}) c.Assert(err, IsNil) c.Check(new, DeepEquals, map[string][]string{ "alias-snap": {"alias4", "alias5"}, }) c.Check(retired, DeepEquals, map[string][]string{ "alias-snap": {"alias3"}, }) }