Skip to content

Commit

Permalink
pr fix: save/restore API in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-rodriguez committed Aug 3, 2023
1 parent 3230fcf commit 64c0b07
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internals/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type daemonSuite struct {
err error
notified []string
restoreBackends func()
savedAPI []*Command
}

var _ = Suite(&daemonSuite{})
Expand All @@ -67,9 +68,15 @@ func (s *daemonSuite) SetUpTest(c *C) {
s.notified = append(s.notified, notif)
return nil
}
if s.savedAPI == nil {
s.savedAPI = make([]*Command, len(API))
copy(s.savedAPI, API)
}
}

func (s *daemonSuite) TearDownTest(c *C) {
copy(API, s.savedAPI)
API = API[:len(s.savedAPI)]
systemdSdNotify = systemd.SdNotify
s.notified = nil
s.authorized = false
Expand Down Expand Up @@ -111,9 +118,7 @@ func (s *daemonSuite) TestAddCommand(c *C) {
GuestOK: true,
GET: getCallback,
}

API = append(API, &command)
defer func() { API = API[:len(API)-1] }()

d := s.newDaemon(c)
d.Init()
Expand Down

0 comments on commit 64c0b07

Please sign in to comment.