Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
mockreaper: implement mock reaper
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mockreaper.go
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() {
}
69 changes: 69 additions & 0 deletions mockreaper_test.go
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()
}

0 comments on commit ecf7f8c

Please sign in to comment.