Skip to content

Commit

Permalink
Improve unit tests for process management
Browse files Browse the repository at this point in the history
There is a test in here for each previously discovered deadlock, race, etc
Generally these issues where surrounding the process replace process.
Since it was not unit tested before.

Signed-off-by: Joshua Moody <joshua.moody@suse.com>
  • Loading branch information
joshimoo authored and innobead committed Jun 22, 2021
1 parent 4c17eb3 commit 6fad907
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 102 deletions.
14 changes: 10 additions & 4 deletions pkg/process/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ func (bc *BinaryCommand) Kill() {
}
}

type MockExecutor struct{}
type MockExecutor struct {
CreationHook func(cmd *MockCommand) (*MockCommand, error)
}

func (me *MockExecutor) NewCommand(name string, arg ...string) (Command, error) {
return NewMockCommand(name, arg...)
cmd := NewMockCommand(name, arg...)
if me.CreationHook == nil {
return cmd, nil
}
return me.CreationHook(NewMockCommand(name, arg...))
}

type MockCommand struct {
Expand All @@ -110,7 +116,7 @@ type MockCommand struct {
stopped bool
}

func NewMockCommand(name string, arg ...string) (*MockCommand, error) {
func NewMockCommand(name string, arg ...string) *MockCommand {
return &MockCommand{
RWMutex: &sync.RWMutex{},

Expand All @@ -121,7 +127,7 @@ func NewMockCommand(name string, arg ...string) (*MockCommand, error) {

started: false,
stopped: false,
}, nil
}
}

func (mc *MockCommand) Run() error {
Expand Down
Loading

0 comments on commit 6fad907

Please sign in to comment.