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

daemon: FakeCommand usage requires reaper.Start() #247

Merged
merged 1 commit into from
Aug 1, 2023
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
5 changes: 5 additions & 0 deletions internals/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/canonical/pebble/internals/overlord/restart"
"github.com/canonical/pebble/internals/overlord/standby"
"github.com/canonical/pebble/internals/overlord/state"
"github.com/canonical/pebble/internals/reaper"
"github.com/canonical/pebble/internals/systemd"
"github.com/canonical/pebble/internals/testutil"
)
Expand All @@ -58,6 +59,8 @@ type daemonSuite struct {
var _ = Suite(&daemonSuite{})

func (s *daemonSuite) SetUpTest(c *C) {
err := reaper.Start()
c.Assert(err, IsNil)
s.pebbleDir = c.MkDir()
s.statePath = filepath.Join(s.pebbleDir, ".pebble.state")
systemdSdNotify = func(notif string) error {
Expand All @@ -71,6 +74,8 @@ func (s *daemonSuite) TearDownTest(c *C) {
s.notified = nil
s.authorized = false
s.err = nil
err := reaper.Stop()
c.Assert(err, IsNil)
}

func (s *daemonSuite) newDaemon(c *C) *Daemon {
Expand Down
19 changes: 19 additions & 0 deletions internals/testutil/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ import (
"path/filepath"

"gopkg.in/check.v1"

"github.com/canonical/pebble/internals/reaper"
)

type fakeCommandSuite struct{}

var _ = check.Suite(&fakeCommandSuite{})

func (s *fakeCommandSuite) SetUpSuite(c *check.C) {
err := reaper.Start()
c.Assert(err, check.IsNil)
}

func (s *fakeCommandSuite) TearDownSuite(c *check.C) {
err := reaper.Stop()
c.Assert(err, check.IsNil)
}

func (s *fakeCommandSuite) TestFakeCommand(c *check.C) {
fake := FakeCommand(c, "cmd", "true", false)
defer fake.Restore()
Expand All @@ -46,6 +58,13 @@ func (s *fakeCommandSuite) TestFakeCommand(c *check.C) {
})
}

func (s *fakeCommandSuite) TestFakeCommandWithReaper(c *check.C) {
fake := FakeCommand(c, "cmd", "true", true)
defer fake.Restore()
err := exec.Command("cmd", "").Run()
c.Assert(err, check.IsNil)
}

func (s *fakeCommandSuite) TestFakeCommandAlso(c *check.C) {
fake := FakeCommand(c, "fst", "", false)
also := fake.Also("snd", "")
Expand Down
Loading