Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/snap: improved robustness of unit tests TestWaitWhileInhibitedGraphicalSession* #12535

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,11 @@ func (s *RunSuite) TestWaitWhileInhibitedGraphicalSessionFlow(c *check.C) {
restoreIsGraphicalSession := snaprun.MockIsGraphicalSession(true)
defer restoreIsGraphicalSession()

restoreTryNotifyRefresh := snaprun.MockTryNotifyRefreshViaSnapDesktopIntegrationFlow(func(snapName string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we add mocking here, it seems like a good opportunity to also add checks here, e.g. c.Check(snapName, Equals, "some-snap") here and in similar places (assuming it's some-snap)

return false, nil
})
defer restoreTryNotifyRefresh()

var notification *usersessionclient.PendingSnapRefreshInfo
restorePendingRefreshNotification := snaprun.MockPendingRefreshNotification(func(refreshInfo *usersessionclient.PendingSnapRefreshInfo) error {
notification = refreshInfo
Expand Down Expand Up @@ -1944,6 +1949,11 @@ func (s *RunSuite) TestWaitWhileInhibitedGraphicalSessionFlowError(c *check.C) {
restoreIsGraphicalSession := snaprun.MockIsGraphicalSession(true)
defer restoreIsGraphicalSession()

restoreTryNotifyRefresh := snaprun.MockTryNotifyRefreshViaSnapDesktopIntegrationFlow(func(snapName string) (bool, error) {
return false, nil
})
defer restoreTryNotifyRefresh()

restorePendingRefreshNotification := snaprun.MockPendingRefreshNotification(func(refreshInfo *usersessionclient.PendingSnapRefreshInfo) error {
return fmt.Errorf("boom")
})
Expand All @@ -1965,6 +1975,11 @@ func (s *RunSuite) TestWaitWhileInhibitedGraphicalSessionFlowErrorOnFinish(c *ch
restoreIsGraphicalSession := snaprun.MockIsGraphicalSession(true)
defer restoreIsGraphicalSession()

restoreTryNotifyRefresh := snaprun.MockTryNotifyRefreshViaSnapDesktopIntegrationFlow(func(snapName string) (bool, error) {
return false, nil
})
defer restoreTryNotifyRefresh()

restorePendingRefreshNotification := snaprun.MockPendingRefreshNotification(func(refreshInfo *usersessionclient.PendingSnapRefreshInfo) error {
return nil
})
Expand Down
8 changes: 8 additions & 0 deletions cmd/snap/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ func MockFinishRefreshNotification(f func(refreshInfo *usersessionclient.Finishe
}
}

func MockTryNotifyRefreshViaSnapDesktopIntegrationFlow(f func(snapName string) (bool, error)) (restore func()) {
old := tryNotifyRefreshViaSnapDesktopIntegrationFlow
tryNotifyRefreshViaSnapDesktopIntegrationFlow = f
return func() {
tryNotifyRefreshViaSnapDesktopIntegrationFlow = old
}
}

func MockAutostartSessionApps(f func(string) error) func() {
old := autostartSessionApps
autostartSessionApps = f
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/inhibit.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var finishRefreshNotification = func(refreshInfo *client.FinishedSnapRefreshInfo
return nil
}

func tryNotifyRefreshViaSnapDesktopIntegrationFlow(snapName string) (bool, error) {
var tryNotifyRefreshViaSnapDesktopIntegrationFlow = func(snapName string) (bool, error) {
// Check if Snapd-Desktop-Integration is available
conn, err := dbusutil.SessionBus()
if err != nil {
Expand Down