forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kata-containers#207 from devimc/reaper/unitTest
implement mockreaper for unit testing
- Loading branch information
Showing
5 changed files
with
150 additions
and
13 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
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
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() | ||
} |
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