Skip to content

Commit

Permalink
daemon: show what will change in the "refresh-all" changes
Browse files Browse the repository at this point in the history
daemon: show what will change in the "refresh-all" changes
  • Loading branch information
mvo5 authored Nov 24, 2016
2 parents 643d508 + 16cc8a0 commit bd645af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 8 additions & 4 deletions daemon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,18 @@ func snapUpdateMany(inst *snapInstruction, st *state.State) (msg string, updated
return "", nil, nil, err
}

switch len(inst.Snaps) {
switch len(updated) {
case 0:
// all snaps
msg = i18n.G("Refresh all snaps in the system")
// not really needed but be paranoid
if len(inst.Snaps) != 0 {
return "", nil, nil, fmt.Errorf("internal error: when asking for a refresh of %s no update was found but no error was generated", quotedNames(inst.Snaps))
}
// FIXME: instead don't generated a change(?) at all
msg = fmt.Sprintf(i18n.G("Refresh all snaps: no updates"))
case 1:
msg = fmt.Sprintf(i18n.G("Refresh snap %q"), inst.Snaps[0])
default:
quoted := quotedNames(inst.Snaps)
quoted := quotedNames(updated)
// TRANSLATORS: the %s is a comma-separated list of quoted snap names
msg = fmt.Sprintf(i18n.G("Refresh snaps %s"), quoted)
}
Expand Down
29 changes: 26 additions & 3 deletions daemon/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ func (s *apiSuite) TestPostSnapsOp(c *check.C) {
st.Lock()
defer st.Unlock()
chg := st.Change(rsp.Change)
c.Check(chg.Summary(), check.Equals, "Refresh all snaps in the system")
c.Check(chg.Summary(), check.Equals, `Refresh snaps "fake1", "fake2"`)
var apiData map[string]interface{}
c.Check(chg.Get("api-data", &apiData), check.IsNil)
c.Check(apiData["snap-names"], check.DeepEquals, []interface{}{"fake1", "fake2"})
Expand All @@ -2432,7 +2432,30 @@ func (s *apiSuite) TestRefreshAll(c *check.C) {
snapstateUpdateMany = func(s *state.State, names []string, userID int) ([]string, []*state.TaskSet, error) {
c.Check(names, check.HasLen, 0)
t := s.NewTask("fake-refresh-all", "Refreshing everything")
return names, []*state.TaskSet{state.NewTaskSet(t)}, nil
return []string{"fake1", "fake2"}, []*state.TaskSet{state.NewTaskSet(t)}, nil
}

d := s.daemon(c)
inst := &snapInstruction{Action: "refresh"}
st := d.overlord.State()
st.Lock()
summary, _, _, err := snapUpdateMany(inst, st)
st.Unlock()
c.Assert(err, check.IsNil)
c.Check(summary, check.Equals, `Refresh snaps "fake1", "fake2"`)
c.Check(refreshSnapDecls, check.Equals, true)
}

func (s *apiSuite) TestRefreshAllNoChanges(c *check.C) {
refreshSnapDecls := false
assertstateRefreshSnapDeclarations = func(s *state.State, userID int) error {
refreshSnapDecls = true
return assertstate.RefreshSnapDeclarations(s, userID)
}

snapstateUpdateMany = func(s *state.State, names []string, userID int) ([]string, []*state.TaskSet, error) {
c.Check(names, check.HasLen, 0)
return nil, nil, nil
}

d := s.daemon(c)
Expand All @@ -2442,7 +2465,7 @@ func (s *apiSuite) TestRefreshAll(c *check.C) {
summary, _, _, err := snapUpdateMany(inst, st)
st.Unlock()
c.Assert(err, check.IsNil)
c.Check(summary, check.Equals, "Refresh all snaps in the system")
c.Check(summary, check.Equals, `Refresh all snaps: no updates`)
c.Check(refreshSnapDecls, check.Equals, true)
}

Expand Down

0 comments on commit bd645af

Please sign in to comment.