-
Notifications
You must be signed in to change notification settings - Fork 86
/
fake.go
49 lines (37 loc) · 956 Bytes
/
fake.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
package backend
import (
"io"
"golang.org/x/net/context"
)
type FakeProvider struct {
logOutput []byte
}
func NewFakeProvider(logOutput []byte) *FakeProvider {
return &FakeProvider{logOutput: logOutput}
}
func (p *FakeProvider) Start(ctx context.Context, _ *StartAttributes) (Instance, error) {
return &FakeInstance{logOutput: p.logOutput}, nil
}
type FakeInstance struct {
logOutput []byte
}
func (i *FakeInstance) UploadScript(ctx context.Context, script []byte) error {
return nil
}
func (i *FakeInstance) RunScript(ctx context.Context, writer io.WriteCloser) (*RunResult, error) {
_, err := writer.Write(i.logOutput)
if err != nil {
return &RunResult{Completed: false}, err
}
err = writer.Close()
if err != nil {
return &RunResult{Completed: true}, err
}
return &RunResult{Completed: true}, nil
}
func (i *FakeInstance) Stop(ctx context.Context) error {
return nil
}
func (i *FakeInstance) ID() string {
return "fake"
}