Skip to content

Commit

Permalink
o/snapstate: add unit tests for doDownloadSnap with and without a sna…
Browse files Browse the repository at this point in the history
…p icon url

Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder committed Jan 31, 2025
1 parent e0a1210 commit 11c11a1
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 2 deletions.
4 changes: 4 additions & 0 deletions overlord/snapstate/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ var (
DiscardSnapIcon = discardSnapIcon
)

func MockStoreDownloadIcon(f func(ctx context.Context, name, targetPath, downloadURL string) error) (restore func()) {
return testutil.Mock(&storeDownloadIcon, f)
}

// link, misc handlers
var (
MissingDisabledServices = missingDisabledServices
Expand Down
6 changes: 4 additions & 2 deletions overlord/snapstate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ func downloadSnapParams(st *state.State, t *state.Task) (*SnapSetup, StoreServic
return snapsup, sto, user, nil
}

var storeDownloadIcon = store.DownloadIcon

func (m *SnapManager) doDownloadSnap(t *state.Task, tomb *tomb.Tomb) error {
st := t.State()
var rate int64
Expand Down Expand Up @@ -789,7 +791,7 @@ func (m *SnapManager) doDownloadSnap(t *state.Task, tomb *tomb.Tomb) error {
logger.Debugf("cannot download snap icon for %q: no icon URL", snapsup.SnapName())
return
}
if iconErr := store.DownloadIcon(ctx, snapsup.SnapName(), targetIconFn, iconURL); iconErr != nil {
if iconErr := storeDownloadIcon(ctx, snapsup.SnapName(), targetIconFn, iconURL); iconErr != nil {
logger.Debugf("cannot download snap icon for %q: %#v", snapsup.SnapName(), iconErr)
}
})
Expand All @@ -806,7 +808,7 @@ func (m *SnapManager) doDownloadSnap(t *state.Task, tomb *tomb.Tomb) error {
logger.Debugf("cannot download snap icon for %q: no icon URL", snapsup.SnapName())
return
}
if iconErr := store.DownloadIcon(ctx, snapsup.SnapName(), targetIconFn, iconURL); iconErr != nil {
if iconErr := storeDownloadIcon(ctx, snapsup.SnapName(), targetIconFn, iconURL); iconErr != nil {
logger.Debugf("cannot download snap icon for %q: %#v", snapsup.SnapName(), iconErr)
}
})
Expand Down
Loading

0 comments on commit 11c11a1

Please sign in to comment.