forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockreaper.go
80 lines (62 loc) · 1.37 KB
/
mockreaper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"bytes"
"errors"
"fmt"
"os/exec"
)
type mockreaper struct {
}
func (r *mockreaper) init() {
}
func (r *mockreaper) getEpoller(pid int) (*epoller, error) {
return nil, nil
}
func (r *mockreaper) setEpoller(pid int, epoller *epoller) {
}
func (r *mockreaper) deleteEpoller(pid int) {
}
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() {
}
func (r *mockreaper) run(c *exec.Cmd) error {
if err := c.Run(); err != nil {
return fmt.Errorf("reaper: Could not start process: %v", err)
}
return nil
}
func (r *mockreaper) combinedOutput(c *exec.Cmd) ([]byte, error) {
if c.Stdout != nil {
return nil, errors.New("reaper: Stdout already set")
}
if c.Stderr != nil {
return nil, errors.New("reaper: Stderr already set")
}
var b bytes.Buffer
c.Stdout = &b
c.Stderr = &b
err := r.run(c)
return b.Bytes(), err
}