This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mockreaper is a helpful struct to write unit tests Signed-off-by: Julio Montes <julio.montes@intel.com>
- Loading branch information
Julio Montes
committed
Apr 4, 2018
1 parent
8461df3
commit ecf7f8c
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package main | ||
|
||
import "os/exec" | ||
|
||
type mockreaper struct { | ||
} | ||
|
||
func (r *mockreaper) init() { | ||
} | ||
|
||
func (r *mockreaper) getExitCodeCh(pid int) (chan<- int, error) { | ||
return nil, nil | ||
} | ||
|
||
func (r *mockreaper) setExitCodeCh(pid int, exitCodeCh chan<- int) { | ||
} | ||
|
||
func (r *mockreaper) deleteExitCodeCh(pid int) { | ||
} | ||
|
||
func (r *mockreaper) reap() error { | ||
return nil | ||
} | ||
|
||
func (r *mockreaper) start(c *exec.Cmd) (<-chan int, error) { | ||
return nil, nil | ||
} | ||
|
||
func (r *mockreaper) wait(exitCodeCh <-chan int, proc waitProcess) (int, error) { | ||
return 0, nil | ||
} | ||
|
||
func (r *mockreaper) lock() { | ||
} | ||
|
||
func (r *mockreaper) unlock() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMockReaperInit(t *testing.T) { | ||
m := &mockreaper{} | ||
m.init() | ||
} | ||
|
||
func TestMockReaperGetExitCodeCh(t *testing.T) { | ||
assert := assert.New(t) | ||
m := &mockreaper{} | ||
c, e := m.getExitCodeCh(0) | ||
assert.Nil(c) | ||
assert.NoError(e) | ||
} | ||
|
||
func TestMockReaperSetExitCodeCh(t *testing.T) { | ||
m := &mockreaper{} | ||
m.setExitCodeCh(0, nil) | ||
} | ||
|
||
func TestMockReaperDeleteExitCodeCh(t *testing.T) { | ||
m := &mockreaper{} | ||
m.deleteExitCodeCh(0) | ||
} | ||
|
||
func TestMockReaperReap(t *testing.T) { | ||
assert := assert.New(t) | ||
m := &mockreaper{} | ||
err := m.reap() | ||
assert.NoError(err) | ||
} | ||
|
||
func TestMockReaperStart(t *testing.T) { | ||
assert := assert.New(t) | ||
m := &mockreaper{} | ||
c, e := m.start(nil) | ||
assert.Nil(c) | ||
assert.NoError(e) | ||
} | ||
|
||
func TestMockReaperWait(t *testing.T) { | ||
assert := assert.New(t) | ||
m := &mockreaper{} | ||
e, err := m.wait(nil, &reaperOSProcess{}) | ||
assert.Equal(0, e) | ||
assert.NoError(err) | ||
} | ||
|
||
func TestMockReaperLock(t *testing.T) { | ||
m := &mockreaper{} | ||
m.lock() | ||
} | ||
|
||
func TestMockReaperUnlock(t *testing.T) { | ||
m := &mockreaper{} | ||
m.unlock() | ||
} |