/
ambassador_mock.go
65 lines (53 loc) · 1.24 KB
/
ambassador_mock.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
package ext
import (
"github.com/stretchr/testify/mock"
"io"
"os/exec"
)
type FakeFile struct {
name string
reader io.Reader
}
// NewFakeFile constructs a new FakeFile with the given name and content.
func NewFakeFile(name string, content io.Reader) *FakeFile {
return &FakeFile{
name: name,
reader: content,
}
}
func (ff *FakeFile) Name() string {
return ff.name
}
func (ff *FakeFile) Read(p []byte) (int, error) {
return ff.reader.Read(p)
}
type MockAmbassador struct {
mock.Mock
}
func NewMockAmbassador() *MockAmbassador {
return &MockAmbassador{}
}
func (m *MockAmbassador) Environ() []string {
args := m.Called()
return args.Get(0).([]string)
}
func (m *MockAmbassador) LookPath(file string) (string, error) {
args := m.Called(file)
return args.String(0), args.Error(1)
}
func (m *MockAmbassador) RunCmd(cmd *exec.Cmd) ([]byte, int, error) {
args := m.Called(cmd)
return args.Get(0).([]byte), args.Int(1), args.Error(2)
}
func (m *MockAmbassador) TempFile(dir, pattern string) (file File, err error) {
args := m.Called(dir, pattern)
if arg := args.Get(0); arg != nil {
file = arg.(File)
}
err = args.Error(1)
return
}
func (m *MockAmbassador) Remove(name string) error {
args := m.Called(name)
return args.Error(0)
}